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

--experimental-specifier-resolution=node doesn't follow the main field in package.json #38739

Closed
hronro opened this issue May 20, 2021 · 2 comments · Fixed by #38979
Closed
Labels
esm Issues and PRs related to the ECMAScript Modules implementation.

Comments

@hronro
Copy link

hronro commented May 20, 2021

What steps will reproduce the bug?

project structure:

├── package.json
└── src
   ├── foo
   │  ├── package.json
   │  └── src
   │     └── index.js
   └── index.js
// package.json
{
  "main": "src/index.js",
  "type": "module"
}
// src/foo/package.json
{
  "main": "src/index.js",
  "type": "module"
}
// src/foo/src/index.js
export default 'foo'
// src/index.js
import foo from './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'
}

Additional information

@aduh95
Copy link
Contributor

aduh95 commented May 20, 2021

@nodejs/modules

@ljharb
Copy link
Member

ljharb commented 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).

@DerekNonGeneric DerekNonGeneric added the esm Issues and PRs related to the ECMAScript Modules implementation. label May 20, 2021
@aduh95 aduh95 closed this as completed in 4e17ffc Jun 13, 2021
danielleadams pushed a commit that referenced this issue Jun 14, 2021
PR-URL: #38979
Fixes: #32103
Fixes: #38739
Reviewed-By: Bradley Farias <[email protected]>
Reviewed-By: Guy Bedford <[email protected]>
danielleadams pushed a commit that referenced this issue Jun 17, 2021
PR-URL: #38979
Fixes: #32103
Fixes: #38739
Reviewed-By: Bradley Farias <[email protected]>
Reviewed-By: Guy Bedford <[email protected]>
richardlau pushed a commit that referenced this issue Jul 19, 2021
PR-URL: #38979
Fixes: #32103
Fixes: #38739
Reviewed-By: Bradley Farias <[email protected]>
Reviewed-By: Guy Bedford <[email protected]>
richardlau pushed a commit that referenced this issue Jul 20, 2021
PR-URL: #38979
Fixes: #32103
Fixes: #38739
Reviewed-By: Bradley Farias <[email protected]>
Reviewed-By: Guy Bedford <[email protected]>
aduh95 added a commit to aduh95/node that referenced this issue Jul 23, 2021
aduh95 added a commit to aduh95/node that referenced this issue Jul 28, 2021
richardlau pushed a commit that referenced this issue Jul 28, 2021
PR-URL: #38979
Backport-PR-URL: #39497
Fixes: #32103
Fixes: #38739
Reviewed-By: Bradley Farias <[email protected]>
Reviewed-By: Guy Bedford <[email protected]>
richardlau pushed a commit that referenced this issue Jul 28, 2021
PR-URL: #38979
Backport-PR-URL: #39497
Fixes: #32103
Fixes: #38739
Reviewed-By: Bradley Farias <[email protected]>
Reviewed-By: Guy Bedford <[email protected]>
foxxyz pushed a commit to foxxyz/node that referenced this issue Oct 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
esm Issues and PRs related to the ECMAScript Modules implementation.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants