maska icon indicating copy to clipboard operation
maska copied to clipboard

ERR_REQUIRE_ESM

Open Mad-Head opened this issue 1 year ago • 9 comments

I import a module in a vue component and get an error on the server side rendering context:

Error [ERR_REQUIRE_ESM]: require() of ES Module /.../node_modules/maska/dist/maska.umd.js from /.../node_modules/vue-server-renderer/build.dev.js not supported.
maska.umd.js is treated as an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which declares all .js files in that package scope as ES modules.
Instead rename maska.umd.js to end in .cjs, change the requiring code to use dynamic import() which is available in all CommonJS modules, or change "type": "module" to "type": "commonjs" in /.../node_modules/maska/package.json to treat all .js files as CommonJS (using .mjs for all ES modules instead).

I use the custom webpack build with vue 2 ssr

Mad-Head avatar May 17 '23 06:05 Mad-Head

I found that the problem goes away if for example i remove "type": "module" from package.json or rename maska.umd.js to maska.umd.cjs

Mad-Head avatar May 17 '23 06:05 Mad-Head

But UMD is not CJS. What about browsers? Looks like we need third format for CJS or some corrections of package.json.

beholdr avatar May 17 '23 12:05 beholdr

I'm not sure, but in my case it worked both in the browser and on ssr. As far as I understand, "type": "module" in the package.json file indicates that the package should be read as ES module and it causes an error when trying to read .umd as an ES module. You may want to remove "type": "module" from package.json?

Mad-Head avatar May 24 '23 05:05 Mad-Head

Could you please provide minimal repo that gives such error?

beholdr avatar May 26 '23 08:05 beholdr

Hi @beholdr it seems this issue has gone stale, but has there been any thought to type: module in package.json? I too am getting this error in vanilla JS setup using Rollup. Similar to Mad-Head removing type: module solves the issue. I was able to get around this by installing v 1.5.2, but I'd love to use the newer features if possible.

Thanks

matt-meagher avatar Jun 26 '23 15:06 matt-meagher

@matt-meagher Hi, can you please create minimal repo with such error?

beholdr avatar Jun 26 '23 15:06 beholdr

Thanks for getting back to me @beholdr. I actually cannot recreate outside of my storybook environment, and unfortunately cannot share that. I'm going to look for alternatives.

matt-meagher avatar Jun 26 '23 18:06 matt-meagher

Jest (jest": "^27.5.1") in tests cannot import this module, although this library itself is tested using Jest, surrealism)

mask

grantorin avatar Nov 17 '23 14:11 grantorin

I have just released v3-beta. Could you check if this issue still actual?

beholdr avatar Jun 02 '24 15:06 beholdr

Closing as inactive.

beholdr avatar Jul 14 '24 18:07 beholdr