Skip to content

module: fix require of imports with package map - #66565

Open
lazerg wants to merge 2 commits into
nodejs:mainfrom
lazerg:fix/issue-66562-package-map-imports
Open

lazerg wants to merge 2 commits into
nodejs:mainfrom
lazerg:fix/issue-66562-package-map-imports

Conversation

@lazerg

@lazerg lazerg commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

With --experimental-package-map, Module._resolveFilename sent every non-relative request to the package map, # specifiers included. The map has no entry for them, so require('#x') threw MODULE_NOT_FOUND before the package.json "imports" lookup could run. This skips the map for # requests, which matches the documented require() algorithm and what the ESM resolver already does.

Fixes: #66562

Signed-off-by: lazerg <lazerg2@gmail.com>
Assisted-by: Claude Code
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/loaders

@nodejs-github-bot nodejs-github-bot added module Issues and PRs related to the module subsystem. needs-ci PRs that need a full CI run. labels Oct 7, 2026
@github-actions

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

Caution

AgentScan found account activity patterns that may be consistent with automation. This is a heuristic, not proof that this pull request was opened by an agent or violates policy. AI-assisted contributions are permitted, but automated tooling must not open pull requests without advance approval, and contributors must personally understand, test, verify, and take responsibility for every submitted change. See the AgentScan analysis, AI use policy, and automation policy for additional context.

@codecov

codecov Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.43%. Comparing base (1bcf30b) to head (8ceb94d).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #66565      +/-   ##
==========================================
- Coverage   92.77%   90.43%   -2.34%     
==========================================
  Files         422      791     +369     
  Lines      193590   276517   +82927     
  Branches    29859    53088   +23229     
==========================================
+ Hits       179597   250070   +70473     
- Misses      13664    16846    +3182     
- Partials      329     9601    +9272     
Files with missing lines Coverage Δ
lib/internal/modules/cjs/loader.js 97.99% <100.00%> (+19.19%) ⬆️

... and 501 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment on lines +136 to +148
const { status, stdout, stderr } = spawnSync(process.execPath, [
'--no-warnings',
'--experimental-package-map', packageMapPath,
'-e',
`const root = require('#root'); console.log(root.default);`,
], {
cwd: fixtures.path('package-map/root'),
encoding: 'utf8',
});

assert.strictEqual(stderr, '');
assert.match(stdout, /root-package/);
assert.strictEqual(status, 0, stderr);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit

Suggested change
const { status, stdout, stderr } = spawnSync(process.execPath, [
'--no-warnings',
'--experimental-package-map', packageMapPath,
'-e',
`const root = require('#root'); console.log(root.default);`,
], {
cwd: fixtures.path('package-map/root'),
encoding: 'utf8',
});
assert.strictEqual(stderr, '');
assert.match(stdout, /root-package/);
assert.strictEqual(status, 0, stderr);
spawnSyncAndAssert(process.execPath, [
'--no-warnings',
'--experimental-package-map', packageMapPath,
'-e',
`const root = require('#root'); console.log(root.default);`,
], {
cwd: fixtures.path('package-map/root'),
encoding: 'utf8',
}, {
stderr: '',
stdout: /root-package/,
});

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 8ceb94d, thanks.

Signed-off-by: lazerg <lazerg2@gmail.com>
Assisted-by: Claude Code
@aduh95 aduh95 added author ready PRs with CI started, the required approvals, and no outstanding review comments. request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. commit-queue-squash PRs the Commit Queue should land as one squashed commit. labels Oct 7, 2026
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Oct 7, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agentscan:community-flagged author ready PRs with CI started, the required approvals, and no outstanding review comments. commit-queue-squash PRs the Commit Queue should land as one squashed commit. module Issues and PRs related to the module subsystem. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

require('#x') subpath imports fail with MODULE_NOT_FOUND under --experimental-package-map

5 participants