Skip to content

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

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

lazerg wants to merge 1 commit 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 (243c4ca).
⚠️ Report is 1 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   276516   +82926     
  Branches    29859    53093   +23234     
==========================================
+ Hits       179597   250073   +70476     
- Misses      13664    16850    +3186     
- Partials      329     9593    +9264     
Files with missing lines Coverage Δ
lib/internal/modules/cjs/loader.js 97.99% <100.00%> (+19.19%) ⬆️

... and 499 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/,
});

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

Labels

agentscan:community-flagged 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

4 participants