Title: `require('#x')` subpath imports fail with MODULE_NOT_FOUND under `--experimental-package-map` · Issue #66562 · nodejs/node · GitHub
Open Graph Title: `require('#x')` subpath imports fail with MODULE_NOT_FOUND under `--experimental-package-map` · Issue #66562 · nodejs/node
X Title: `require('#x')` subpath imports fail with MODULE_NOT_FOUND under `--experimental-package-map` · Issue #66562 · nodejs/node
Description: Version v26.10.0 (also v26.8.1) Platform Microsoft Windows NT 10.0.26100.0 x64 , package maps Subsystem module, package maps What steps will reproduce the bug? A CommonJS module cannot require() one of its own package's "imports" entries...
Open Graph Description: Version v26.10.0 (also v26.8.1) Platform Microsoft Windows NT 10.0.26100.0 x64 , package maps Subsystem module, package maps What steps will reproduce the bug? A CommonJS module cannot require() on...
X Description: Version v26.10.0 (also v26.8.1) Platform Microsoft Windows NT 10.0.26100.0 x64 , package maps Subsystem module, package maps What steps will reproduce the bug? A CommonJS module cannot require() on...
Opengraph URL: https://github.com/nodejs/node/issues/66562
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`require('#x')` subpath imports fail with MODULE_NOT_FOUND under `--experimental-package-map`","articleBody":"### Version\n\nv26.10.0 (also v26.8.1)\n\n### Platform\n\n```text\nMicrosoft Windows NT 10.0.26100.0 x64\n, package maps\n```\n\n### Subsystem\n\nmodule, package maps\n\n### What steps will reproduce the bug?\n\nA CommonJS module cannot `require()` one of its own package's `\"imports\"` entries when a package map is active. ESM `import` of the same specifier works.\n\n```text\npkg/package.json {\"name\":\"pkg\",\"version\":\"1.0.0\",\"imports\":{\"#*\":\"./src/*\"},\"main\":\"./index.cjs\"}\npkg/index.cjs module.exports = require('#util.cjs');\npkg/src/util.cjs module.exports = 'ok';\napp/package.json {\"type\":\"module\"}\napp/a.cjs console.log(require('pkg'));\nmap.json {\"packages\":{\"app\":{\"url\":\"./app\",\"dependencies\":{\"pkg\":\"pkg\"}},\"pkg\":{\"url\":\"./pkg\",\"dependencies\":{}}}}\n```\n\n```console\n$ node --experimental-package-map=map.json app/a.cjs\nError: Cannot find module '#util.cjs'\n```\n\n### How often does it reproduce? Is there a required condition?\n\nAlways, when `--experimental-package-map` is set and a CommonJS module requires a `#` specifier.\n\n### What is the expected behavior? Why is that the expected behavior?\n\n`ok` is printed, as it is without the flag.\n\nThe `require()` algorithm in [modules.md](https://github.com/nodejs/node/blob/c89ec290f0f82f544e39e6e5f2eab3b6de2c1cca/doc/api/modules.md?plain=1#L342-L358) runs `LOAD_PACKAGE_IMPORTS` (step 4) and `LOAD_PACKAGE_SELF` (step 5) before `LOAD_PACKAGE_MAP` (step 6). The ESM resolver also sends `#` specifiers to [`packageImportsResolve`](https://github.com/nodejs/node/blob/c89ec290f0f82f544e39e6e5f2eab3b6de2c1cca/lib/internal/modules/esm/resolve.js#L828-L829) and asks the map only in [`packageResolve`](https://github.com/nodejs/node/blob/c89ec290f0f82f544e39e6e5f2eab3b6de2c1cca/lib/internal/modules/esm/resolve.js#L737-L740).\n\n### What do you see instead?\n\n```console\nError: Cannot find module '#util.cjs'\n code: 'MODULE_NOT_FOUND'\n```\n\n### Additional information\n\nCause, in `lib/internal/modules/cjs/loader.js` (main at c89ec290f0):\n\n* [`Module._resolveFilename`](https://github.com/nodejs/node/blob/c89ec290f0f82f544e39e6e5f2eab3b6de2c1cca/lib/internal/modules/cjs/loader.js#L1526-L1531) calls `tryPackageMapResolveCJS` for every request that is not relative and not absolute. `#` requests are included.\n* [`tryPackageMapResolveCJS`](https://github.com/nodejs/node/blob/c89ec290f0f82f544e39e6e5f2eab3b6de2c1cca/lib/internal/modules/cjs/loader.js#L697-L712) throws MODULE_NOT_FOUND when the map has no entry for the request.\n* The [`#` imports block](https://github.com/nodejs/node/blob/c89ec290f0f82f544e39e6e5f2eab3b6de2c1cca/lib/internal/modules/cjs/loader.js#L1567-L1573) is never reached.\n\nSuggested fix: do the map lookup after the `#` imports step (and after `trySelf`), as the documented algorithm does, or skip the lookup for requests that start with `#`.\n\nPublished packages that use `\"imports\"` from CommonJS fail to load under a package map. For example, dependency-cruiser 18.2.0 has `require(\"#utl/try-require.cjs\")` in `src/extract/transpile/vue-template-wrap.cjs`. I found it through pnpm's `nodeExperimentalPackageMap` setting.\n\nThis was triaged using Opus 5.5 but verified by me to the best of my ability and filed by myself.","author":{"url":"https://github.com/christopher-buss","@type":"Person","name":"christopher-buss"},"datePublished":"2026-10-06T18:04:47Z","url":"https://github.com/nodejs/node/issues/66562"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react-reconciler,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@d5750093facf |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:547ec7ac-2250-bf69-6c56-4f9f25a56000 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | AE1A:FF56D:10650C:161EB4:6AED3581 |
| html-safe-nonce | 848704394ec1198e2e1e0d2dae4d39f505304e6ba4412e0bb7c47537704ff683 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBRTFBOkZGNTZEOjEwNjUwQzoxNjFFQjQ6NkFFRDM1ODEiLCJ2aXNpdG9yX2lkIjoiMTc1NDMyMjYzOTg3MDgzNDA0OSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 6bebe86149a0d831205f20dea0eab623223fdf8c72ff4367e870f1b5c90a7add |
| hovercard-subject-tag | issue:5733146723 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/nodejs/node/66562/issue_layout |
| twitter:image | https://opengraph.githubassets.com/e30c6463f72bba45df3c69b53388d468a6f2e65c0e5dd9304013e9e89c00284f/nodejs/node/issues/66562 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/e30c6463f72bba45df3c69b53388d468a6f2e65c0e5dd9304013e9e89c00284f/nodejs/node/issues/66562 |
| og:image:alt | Version v26.10.0 (also v26.8.1) Platform Microsoft Windows NT 10.0.26100.0 x64 , package maps Subsystem module, package maps What steps will reproduce the bug? A CommonJS module cannot require() on... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | christopher-buss |
| hostname | github.com |
| expected-hostname | github.com |
| None | 26c92a9388ddfad3fa88d132b5d5f0b4747030233dcc4e5efb05f1cbae152184 |
| turbo-cache-control | no-preview |
| go-import | github.com/nodejs/node git https://github.com/nodejs/node.git |
| octolytics-dimension-user_id | 9950313 |
| octolytics-dimension-user_login | nodejs |
| octolytics-dimension-repository_id | 27193779 |
| octolytics-dimension-repository_nwo | nodejs/node |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 27193779 |
| octolytics-dimension-repository_network_root_nwo | nodejs/node |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | c629ad99c254d306375fc8354d04321c2c362236 |
| ui-target | canary-1 |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width