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
{{ message }}
Repository navigation
--experimental-specifier-resolution=node doesn't follow the main field in package.json #38739
// src/index.jsimportfoofrom'./foo'console.log(`hello from ${foo}`)
Run node --experimental-specifier-resolution=node .
How often does it reproduce? Is there a required condition?
Always
What is the expected behavior?
Should see hello from foo in the terminal
What do you see instead?
node:internal/process/esm_loader:74
internalBinding('errors').triggerUncaughtException(
^
Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/xxx/src/foo' imported from /xxx/src/index.js
at new NodeError (node:internal/errors:363:5)
at finalizeResolution (node:internal/modules/esm/resolve:296:11)
at moduleResolve (node:internal/modules/esm/resolve:742:10)
at Loader.defaultResolve [as _resolve] (node:internal/modules/esm/resolve:853:11)
at Loader.resolve (node:internal/modules/esm/loader:89:40)
at Loader.getModuleJob (node:internal/modules/esm/loader:242:28)
at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:73:40)
at link (node:internal/modules/esm/module_job:72:36) {
code: 'ERR_MODULE_NOT_FOUND'
}
Activity
aduh95 commentedon May 20, 2021
@nodejs/modules
ljharb commentedon May 20, 2021
I believe this is quite intentional; see #36918.
Especially when using ESM, the intention is to use
"exports"and not"main"(altho a published package should ofc provide both, for back compat).module: fix legacy `node` specifier resolution to resolve `"main"` field
module: fix legacy `node` specifier resolution to resolve `"main"` field
module: fix legacy `node` specifier resolution to resolve `"main"` field
module: fix legacy `node` specifier resolution to resolve `"main"` field
module: fix legacy `node` specifier resolution to resolve `"main"` field
module: fix legacy `node` specifier resolution to resolve `"main"` field