formidable icon indicating copy to clipboard operation
formidable copied to clipboard

fix: vendor hexoid until v2 is released

Open icholy opened this issue 1 year ago • 0 comments

Problem:

The v1.0.0 release of hexoid is incompatible with webpack.

main.js

require('formidable');

webpack.config.js

module.exports = {
	target: 'node',
	entry: './main.js',
	optimization: {
		minimize: false
	}
}

Output:

/home/icholy/src/playground/hexoid-webpack/dist/main.js:1381
const toHexoId = hexoid(25);
                 ^

TypeError: hexoid is not a function
    at 211 (/home/icholy/src/playground/hexoid-webpack/dist/main.js:1381:18)
    at __webpack_require__ (/home/icholy/src/playground/hexoid-webpack/dist/main.js:2121:41)
    at /home/icholy/src/playground/hexoid-webpack/dist/main.js:2158:1
    at Object.<anonymous> (/home/icholy/src/playground/hexoid-webpack/dist/main.js:2160:12)
    at Module._compile (node:internal/modules/cjs/loader:1376:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1435:10)
    at Module.load (node:internal/modules/cjs/loader:1207:32)
    at Module._load (node:internal/modules/cjs/loader:1023:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:135:12)
    at node:internal/main/run_main_module:28:49

Root Cause:

Webpack prefers the module entry over the main entry in package.json by default, but hexoid exports incompatible APIs between the commonjs & esm modules. The esm module uses a default export which is not equivalent to the module.exports assignment in the commonjs module.

Solution 1:

The hexoid repo has fixed the inconsistency in their master branch, but haven't published a release in 4 years. I've requested a v2 be published with the new exports. Once this happens, we can upgrade to that: https://github.com/lukeed/hexoid/issues/7

Solution 2:

In the meantime, I propose that we vendor the hexoid code as a helper function.

icholy avatar Jul 30 '24 15:07 icholy