libphonenumber-js
libphonenumber-js copied to clipboard
Error [ERR_REQUIRE_ESM] on parsePhoneNumberFromString
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?
Perhaps the Node.js version on the server is lower than the one on your local machine.
No, same version.
Server
Mine
Dunno.
If you're using import
and using the same bundler (or no bundler) then there shouldn't generally be any differences.
There have been reports of issues with the type: 'module'
property, but it won't be removed from this package.