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

Error [ERR_REQUIRE_ESM] on parsePhoneNumberFromString #432

Open
balenaultra opened this issue Oct 5, 2022 · 4 comments
Open

Error [ERR_REQUIRE_ESM] on parsePhoneNumberFromString #432

balenaultra opened this issue Oct 5, 2022 · 4 comments

Comments

@balenaultra
Copy link

I've getting this error when run it on a server of my company

On my computer it runs fine.

ernal/modules/cjs/loader.js:1080
      throw new ERR_REQUIRE_ESM(filename, parentPath, packageJsonPath);
      ^

Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: C:\Ultra WS\UltraAtendimentoRest - 3412\node_modules\libphonenumber-js\build\parsePhoneNumberFromString.js
require() of ES modules is not supported.
require() of C:\Ultra WS\UltraAtendimentoRest - 3412\node_modules\libphonenumber-js\build\parsePhoneNumberFromString.js from C:\Ultra WS\UltraAtendimentoRest - 3412\node_modules\libphonenumber-js\core\index.cjs is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename parsePhoneNumberFromString.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from C:\Ultra WS\UltraAtendimentoRest - 3412\node_modules\libphonenumber-js\package.json.

←[90m    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1080:13)←[39m
←[90m    at Module.load (internal/modules/cjs/loader.js:928:32)←[39m
←[90m    at Function.Module._load (internal/modules/cjs/loader.js:769:14)←[39m
←[90m    at Module.require (internal/modules/cjs/loader.js:952:19)←[39m
←[90m    at require (internal/modules/cjs/helpers.js:88:18)←[39m
    at Object.<anonymous> (C:\Ultra WS\UltraAtendimentoRest - 3412\node_modules\←[4mlibphonenumber-js←[24m\core\index.cjs:3:34)
←[90m    at Module._compile (internal/modules/cjs/loader.js:1063:30)←[39m
←[90m    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)←[39m
←[90m    at Module.load (internal/modules/cjs/loader.js:928:32)←[39m
←[90m    at Function.Module._load (internal/modules/cjs/loader.js:769:14)←[39m {
  code: ←[32m'ERR_REQUIRE_ESM'←[39m
}

Node version: v14.15.1

To fix it, for now, i just remove the "type": "module" from the package.json but it happens in every project from my pc.

Anyone can help me?

@catamphetamine
Copy link
Owner

Perhaps the Node.js version on the server is lower than the one on your local machine.

@balenaultra
Copy link
Author

No, same version.
Server
image

Mine
image

@catamphetamine
Copy link
Owner

Dunno.
If you're using import and using the same bundler (or no bundler) then there shouldn't generally be any differences.

@catamphetamine
Copy link
Owner

There have been reports of issues with the type: 'module' property, but it won't be removed from this package.

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