You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What Node versions, OSs and CPU architectures are you building for?
default
Describe the Bug
Error [ERR_REQUIRE_ESM]: require() of ES Module C:\snapshot\pkg\node_modules\libphonenumber-js\build\parsePhoneNumber.js from C:\snapshot\pkg\node_modules\libphonenumber-js\core\index.cjs not supported. parsePhoneNumber.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 parsePhoneNumber.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 C:\snapshot\pkg\node_modules\libphonenumber-js\package.json to treat all .js files as CommonJS (using .mjs for all ES modules instead). at Module.require (pkg/prelude/bootstrap.js:1851:31) at Object.<anonymous> (C:\snapshot\pkg\node_modules\libphonenumber-js\core\index.cjs:3:34) at Module._compile (pkg/prelude/bootstrap.js:1930:22) at Module.require (pkg/prelude/bootstrap.js:1851:31) at Object.<anonymous> (C:\snapshot\pkg\node_modules\libphonenumber-js\mobile\index.cjs:4:12) at Module._compile (pkg/prelude/bootstrap.js:1930:22) at Module.require (pkg/prelude/bootstrap.js:1851:31) at Object.<anonymous> (C:\snapshot\pkg\index.js:1:88) at Module._compile (pkg/prelude/bootstrap.js:1930:22) at Function.runMain (pkg/prelude/bootstrap.js:1983:12) { code: 'ERR_REQUIRE_ESM' } Node.js v18.19.0
Similar error message I see when I build it for node:18-alpine docker image
Expected Behavior
With v5.10.0 I have no errors and I expect new versions to work as well.
@paulish it was working with 5.10.0 because nodejs 18.19.0 (introduced with 5.11) doesn't require you to enable esm with a flag (like it happened with previous versions) so the resolve module triggers. The solution for you is to stay on 5.10 or consider one of the solutions proposed in my comment linked above
What version of pkg are you using?
5.11.3
Which version(s) of pkg work for you?
5.10.0
What version of Node.js are you using?
18.0.0, 18.19.0
What operating system are you using?
Windows, Alpine linux
What CPU architecture are you using?
x86_64
What Node versions, OSs and CPU architectures are you building for?
default
Describe the Bug
Error [ERR_REQUIRE_ESM]: require() of ES Module C:\snapshot\pkg\node_modules\libphonenumber-js\build\parsePhoneNumber.js from C:\snapshot\pkg\node_modules\libphonenumber-js\core\index.cjs not supported. parsePhoneNumber.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 parsePhoneNumber.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 C:\snapshot\pkg\node_modules\libphonenumber-js\package.json to treat all .js files as CommonJS (using .mjs for all ES modules instead). at Module.require (pkg/prelude/bootstrap.js:1851:31) at Object.<anonymous> (C:\snapshot\pkg\node_modules\libphonenumber-js\core\index.cjs:3:34) at Module._compile (pkg/prelude/bootstrap.js:1930:22) at Module.require (pkg/prelude/bootstrap.js:1851:31) at Object.<anonymous> (C:\snapshot\pkg\node_modules\libphonenumber-js\mobile\index.cjs:4:12) at Module._compile (pkg/prelude/bootstrap.js:1930:22) at Module.require (pkg/prelude/bootstrap.js:1851:31) at Object.<anonymous> (C:\snapshot\pkg\index.js:1:88) at Module._compile (pkg/prelude/bootstrap.js:1930:22) at Function.runMain (pkg/prelude/bootstrap.js:1983:12) { code: 'ERR_REQUIRE_ESM' } Node.js v18.19.0
Similar error message I see when I build it for node:18-alpine docker image
Expected Behavior
With v5.10.0 I have no errors and I expect new versions to work as well.
To Reproduce
pkg_test.zip
Here I uploaded a minimal example to reproduce. Please create an executable with
npm run build
and try to run it.The text was updated successfully, but these errors were encountered: