Repository navigation
--es-module-specifier-resolution=node not working from v13.0.1 #30520
Description
Activity
The fix for this would be to ensure that
.mjsis included inrequire.extensionswhen this flag is enabled.This is because the CJS loader is doing the main entry resolution, and does not include
.mjsresolution by default in itsrequire.extensionslist.A way to get it to work would be to write:
extensions.js
require._extensions['.mjs'] = require._extensions['.js'];
which would allow:
node -r extensions.js --es-module-specifier-resolution=node indexA PR to add this when the flag is set is welcome.
Reacted by Jordan Harband@guybedford Thanks for the explanation.
I tried to create a PR to fix this issue: #30574. Please correct me if I understand it wrong.
- added a commit that references this issue
on Nov 28, 2019 - added a commit that references this issue
on Nov 30, 2019 - added a commit that references this issue
on Jan 12, 2020 - added a commit that references this issue
on Feb 6, 2020 Has this flag been renamed to
experimental-specifier-resolution?@dandv we have renamed the flag, but we continue to support
--es-module-specifier-resolution=nodewhich silently aliases to--experimnetal-specifier-resolutionReacted by Sebastian Schwarz, Norman Pellet and Vincent RugeReacted by Dibo and Walter Cardona@guybedford when I create
extensions.jsas you describe and run:$ cat extensions.js // https://github.com/nodejs/node/issues/30520 require._extensions['.mjs'] = require._extensions['.js']; $ node -r extensions.js --es-module-specifier-resolution=node --experimental-modules lib/server/main.jsI get:
internal/modules/cjs/loader.js:979 throw err; ^ Error: Cannot find module 'extensions.js' Require stack: - internal/preload at Function.Module._resolveFilename (internal/modules/cjs/loader.js:976:15) at Function.Module._load (internal/modules/cjs/loader.js:859:27) at Module.require (internal/modules/cjs/loader.js:1036:19) at Module._preloadModules (internal/modules/cjs/loader.js:1292:12) at loadPreloadModules (internal/bootstrap/pre_execution.js:448:5) at prepareMainThreadExecution (internal/bootstrap/pre_execution.js:71:3) at internal/main/run_main_module.js:7:1 { code: 'MODULE_NOT_FOUND', requireStack: [ 'internal/preload' ] }what am I missing?
@dandv we have renamed the flag, but we continue to support --es-module-specifier-resolution=node which silently aliases to --experimnetal-specifier-resolution
@MylesBorins I'm in Node 14.8 and trying to use
--experimnetal-specifier-resolutiongives menode: bad option: --experimnetal-specifier-resolutionhowever using
--es-module-specifier-resolution=nodeworks.@trusktr
experimental, notexperimnetal?Oops, I copy-pasted from above. xD
Ironically fixing the typo wasn't all. It requires a value:
--experimental-specifier-resolution=nodeReacted by Jordan Harband, Yan , Joey Goertzen and Sebastian Schwarzgetting this error
node: bad option: --es-module-specifier-resolution=node
Node version: 10.19.0@Santosh-13 That flag is working on Node 12 and up.
node v16.13.1, Windows 10
getting this error
Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/C:/[local]/dist-gh-pages/src/common/GreeterUse.js' imported from C:\[local]\dist-gh-pages\src\main.js at new NodeError (node:internal/errors:371:5) at finalizeResolution (node:internal/modules/esm/resolve:405:11) at moduleResolve (node:internal/modules/esm/resolve:932:10) at defaultResolve (node:internal/modules/esm/resolve:1044:11) at ESMLoader.resolve (node:internal/modules/esm/loader:422:30) at ESMLoader.getModuleJob (node:internal/modules/esm/loader:222:40) at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:76:40) at link (node:internal/modules/esm/module_job:75:36) { code: 'ERR_MODULE_NOT_FOUND' }with script
"greetnode": "node --experimental-modules --es-module-specifier-resolution=node ./src/main.js"
and package.json"type": "module", "imports": { "#common/*": "./src/common/*.js" },Now it is the expected behaviour?
How can I run script without errors?Reacted by Joseph Burns@viT-1 I've been getting the same issue for days. I'm also using node v16.13.1
Imports of ES^ module in my app are not resolved
- This thread says that you have to add the '.js' extension to solve the problem but that didn't work for me.
That's my ts.config.server.json
{ "extends": "./tsconfig.json", "compilerOptions": { "jsx": "react", "baseUrl": ".", "module": "esnext", "target": "esnext", "paths": { "~/*": ["*"], "@today/shared/*": ["../../node_modules/@today/shared/dist/*"] }, "outDir": ".next/", "downlevelIteration": true, }, "include": ["server"] }ts-node command
NODE_OPTIONS="--loader ts-node/esm --es-module-specifier-resolution=node" NODE_ENV=development NEXT_PUBLIC_RUNNING_LOCAL_INSTANCE=true ts-node -r tsconfig-paths/register --project ./tsconfig.server.json server/index.mjs --watch 'src/**/*.ts' --ignore 'src/**/*.spec.ts'fails with
Cannot find module '/node_modules/@todaytix/shared/config/server/ssl.js' imported from /websites/lt-nytg/server/index.mjs@jaybe78 For ts-project I solved aliases 2 years ago.
--es-module-specifier-resolution=nodeis documented for v13.x:Here is the specific example that works in v13.0.0, but not in v13.0.1 or v13.1.0:
As you can see in the screenshot above, the error is: