Title: Package map entry whose url resolves to a directory-form URL never matches its files · Issue #66043 · nodejs/node · GitHub
Open Graph Title: Package map entry whose url resolves to a directory-form URL never matches its files · Issue #66043 · nodejs/node
X Title: Package map entry whose url resolves to a directory-form URL never matches its files · Issue #66043 · nodejs/node
Description: Version v26.8.1 Platform Windows 11 x64 (the mechanism is platform independent; see analysis) Subsystem module, package maps What steps will reproduce the bug? A package entry whose url resolves to a directory-form URL (one ending in /) ...
Open Graph Description: Version v26.8.1 Platform Windows 11 x64 (the mechanism is platform independent; see analysis) Subsystem module, package maps What steps will reproduce the bug? A package entry whose url resolves to...
X Description: Version v26.8.1 Platform Windows 11 x64 (the mechanism is platform independent; see analysis) Subsystem module, package maps What steps will reproduce the bug? A package entry whose url resolves to...
Opengraph URL: https://github.com/nodejs/node/issues/66043
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Package map entry whose url resolves to a directory-form URL never matches its files","articleBody":"### Version\n\nv26.8.1\n\n### Platform\n\nWindows 11 x64 (the mechanism is platform independent; see analysis)\n\n### Subsystem\n\nmodule, package maps\n\n### What steps will reproduce the bug?\n\nA package entry whose `url` resolves to a *directory-form* URL (one ending in `/`) never matches any file inside it. The natural relative spellings for \"the directory above the map file\" — `\"..\"`, `\"../\"`, `\".\"`, `\"./\"` — all produce such a URL.\n\n```\nproject/\n package.json {\"private\":true}\n index.cjs console.log(require(\"dep\"));\n node_modules/\n .package-map.json\n dep/package.json {\"name\":\"dep\",\"main\":\"index.cjs\"}\n dep/index.cjs module.exports=\"ok\";\n```\n\n`node_modules/.package-map.json`:\n\n```json\n{\n \"packages\": {\n \"root\": { \"url\": \"..\", \"dependencies\": { \"dep\": \"dep\" } },\n \"dep\": { \"url\": \"./dep\", \"dependencies\": {} }\n }\n}\n```\n\n```console\n$ node --experimental-package-map=node_modules/.package-map.json index.cjs\n```\n\n### How often does it reproduce? Is there a required condition?\n\nAlways. The condition is that the entry's `url` resolves to a URL ending in `/`.\n\nResults for the same map with only the root `url` changed:\n\n| root `url` | result |\n| --- | --- |\n| `\"..\"` | `ERR_PACKAGE_MAP_EXTERNAL_FILE` |\n| `\"../\"` | `ERR_PACKAGE_MAP_EXTERNAL_FILE` |\n| `\".\"` | `ERR_PACKAGE_MAP_EXTERNAL_FILE` |\n| `\"./\"` | `ERR_PACKAGE_MAP_EXTERNAL_FILE` |\n| absolute `file:` URL without a trailing slash | `ok` |\n\n### What is the expected behavior? Why is that the expected behavior?\n\n`require(\"dep\")` from `index.cjs` should print `ok`. The documentation says `url` is \"An absolute or relative URL ... parsed using the WHATWG `URL` API, using the configuration file URL as base\", and puts no restriction on directory-form URLs. `\".\"` and `\"..\"` are ordinary relative URLs that denote directories, which is what a package entry points at.\n\n### What do you see instead?\n\n```\nError [ERR_PACKAGE_MAP_EXTERNAL_FILE]: Cannot resolve \"dep\" from \".../nodemap/index.cjs\": file is not within any package defined in .../nodemap/node_modules/.package-map.json\n at PackageMap.resolve (node:internal/modules/package_map:179:13)\n at packageMapResolve (node:internal/modules/package_map:305:14)\n at tryPackageMapResolveCJS (node:internal/modules/cjs/loader:697:18)\n code: 'ERR_PACKAGE_MAP_EXTERNAL_FILE'\n```\n\n### Additional information\n\nCause, in `lib/internal/modules/package_map.js` (v26.8.1):\n\n* `#parse` stores the package path unnormalized: `absolutePath = fileURLToPath(packageURL)` followed by `this.#pathToKey.set(absolutePath, key)`. For a directory-form URL this keeps the trailing separator, for example `/home/u/proj/`.\n* `#getKeyForPath` does `filePath = pathResolve(filePath)` and then walks up with `dirname`, comparing by exact string. `pathResolve` and `dirname` never yield a trailing separator except at a filesystem root, so the stored key is unreachable and `resolve()` throws `ERR_PACKAGE_MAP_EXTERNAL_FILE`.\n\nThe same reasoning applies on POSIX: `fileURLToPath` keeps the trailing `/`, and `path.posix.dirname(\"/home/u/proj/index.cjs\")` is `/home/u/proj`.\n\nSuggested fix: normalize when storing, that is `absolutePath = pathResolve(fileURLToPath(packageURL))` in `#parse`, so stored paths, duplicate detection and lookup all use the same spelling. Normalizing only in `#getKeyForPath` would leave the stored identity inconsistent.\n\nTest coverage: the fixtures in `test/fixtures/package-map/` use only `\"./name\"` style URLs, so no test exercises a directory-form URL. A regression test could add an entry with `url: \"..\"` and require a dependency from a file in that directory.\n\nThis is not the same as #65501 / #65502, which concern subpaths escaping the target package directory.\n\nFound via pnpm, which writes `\"url\": \"..\"` for the workspace root importer in `node_modules/.package-map.json`, so no file at a project root can resolve a bare specifier.\n","author":{"url":"https://github.com/christopher-buss","@type":"Person","name":"christopher-buss"},"datePublished":"2026-09-15T23:50:34Z","url":"https://github.com/nodejs/node/issues/66043"}
| 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:3210176a-eb34-8031-8743-a1be9d567d6e |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9D2A:2973C7:7A6D6E:9EC873:6AED32E9 |
| html-safe-nonce | ffbe11f4e63e4fe43cff5016233d2ff650a4e8e5f85ad579b34d475570074239 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5RDJBOjI5NzNDNzo3QTZENkU6OUVDODczOjZBRUQzMkU5IiwidmlzaXRvcl9pZCI6IjU1OTM3MzYxMTIxMzI0MDM5NDUiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | cbf2d2a6fc13d1c5d247d40dd233e691d669c8a7ef6ad3a8b72830f5439d17ed |
| hovercard-subject-tag | issue:5468554136 |
| 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/66043/issue_layout |
| twitter:image | https://opengraph.githubassets.com/c3d5310c5e6e14cc0212895d526b54aa64ff13bf20d31bee4df5080b9e27d4b6/nodejs/node/issues/66043 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/c3d5310c5e6e14cc0212895d526b54aa64ff13bf20d31bee4df5080b9e27d4b6/nodejs/node/issues/66043 |
| og:image:alt | Version v26.8.1 Platform Windows 11 x64 (the mechanism is platform independent; see analysis) Subsystem module, package maps What steps will reproduce the bug? A package entry whose url resolves to... |
| 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 | e51d0b7b5ab34b1688c05b54c3ed17b8658b2fa9bca973a9c740683ccb12cf4a |
| 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 | 59ebb7b901cc154ecc179a44f266fcf69f343b30 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width