Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

executable does not start when using libphonenumber-js package #32

Closed
paulish opened this issue Feb 15, 2024 · 3 comments
Closed

executable does not start when using libphonenumber-js package #32

paulish opened this issue Feb 15, 2024 · 3 comments

Comments

@paulish
Copy link

paulish commented Feb 15, 2024

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.

@robertsLando
Copy link
Member

Dup of: #16 (comment)

@paulish
Copy link
Author

paulish commented Feb 15, 2024

@robertsLando have you read that it works correctly with 5.10.0? Therefore this is a regression instead of duplicate a missing feature.

@robertsLando
Copy link
Member

robertsLando commented Feb 15, 2024

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants