Not possible to use this library in "type":"module" package
jorenbroekema opened this issue · 0 comments
jorenbroekema commented
Error [ERR_REQUIRE_ESM]: require() of ES Module /foo/i18n/index.js from /foo/node_modules/next-export-i18n/index.js not supported.
/foo/i18n/index.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 either rename /foo/i18n/index.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 /foo/package.json to treat all .js files as CommonJS (using .mjs for all ES modules instead).
This error occurs when using this library in an ESM project which uses "type": "module"
in package.json
.
Renaming the index.js
to index.cjs
does not work because the filename is hardcoded: https://github.com/martinkr/next-export-i18n/blob/main/module/src/index.tsx#L5
Can we find a way to support a .cjs
file or to support ESM?