Package map entry whose url resolves to a directory-form URL never matches its files
Maintainer antworten meist innerhalb von 1 Tag
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Anfängerfreundlichkeit
- 78/100
- Issue-Typ
- Bug
- Klarheit
- Klar beschrieben
- Aktivitätsstatus
- Aktiv
- Tech-Stack
- javascript
- Bereich
- backend
Rechercherichtung
Lies lib/internal/modules/package_map.js, insbesondere #parse und #getKeyForPath, und untersuche anschließend die Fixtures unter test/fixtures/package-map/. Füge einen Regressionstest hinzu, der eine URL in Verzeichnisform wie ".." verwendet, und überprüfe, dass das Anfordern der Abhängigkeit erfolgreich aufgelöst wird, statt ERR_PACKAGE_MAP_EXTERNAL_FILE auszulösen.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
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 /) never matches any file inside it. The natural relative spellings for "the directory above the map file" — "..", "../", ".", "./" — all produce such a URL.
project/
package.json {"private":true}
index.cjs console.log(require("dep"));
node_modules/
.package-map.json
dep/package.json {"name":"dep","main":"index.cjs"}
dep/index.cjs module.exports="ok";
node_modules/.package-map.json:
{
"packages": {
"root": { "url": "..", "dependencies": { "dep": "dep" } },
"dep": { "url": "./dep", "dependencies": {} }
}
}
$ node --experimental-package-map=node_modules/.package-map.json index.cjs
How often does it reproduce? Is there a required condition?
Always. The condition is that the entry's url resolves to a URL ending in /.
Results for the same map with only the root url changed:
root url |
result |
|---|---|
".." |
ERR_PACKAGE_MAP_EXTERNAL_FILE |
"../" |
ERR_PACKAGE_MAP_EXTERNAL_FILE |
"." |
ERR_PACKAGE_MAP_EXTERNAL_FILE |
"./" |
ERR_PACKAGE_MAP_EXTERNAL_FILE |
absolute file: URL without a trailing slash |
ok |
What is the expected behavior? Why is that the expected behavior?
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.
What do you see instead?
Error [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
at PackageMap.resolve (node:internal/modules/package_map:179:13)
at packageMapResolve (node:internal/modules/package_map:305:14)
at tryPackageMapResolveCJS (node:internal/modules/cjs/loader:697:18)
code: 'ERR_PACKAGE_MAP_EXTERNAL_FILE'
Additional information
Cause, in lib/internal/modules/package_map.js (v26.8.1):
#parsestores the package path unnormalized:absolutePath = fileURLToPath(packageURL)followed bythis.#pathToKey.set(absolutePath, key). For a directory-form URL this keeps the trailing separator, for example/home/u/proj/.#getKeyForPathdoesfilePath = pathResolve(filePath)and then walks up withdirname, comparing by exact string.pathResolveanddirnamenever yield a trailing separator except at a filesystem root, so the stored key is unreachable andresolve()throwsERR_PACKAGE_MAP_EXTERNAL_FILE.
The same reasoning applies on POSIX: fileURLToPath keeps the trailing /, and path.posix.dirname("/home/u/proj/index.cjs") is /home/u/proj.
Suggested 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.
Test 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.
This is not the same as #65501 / #65502, which concern subpaths escaping the target package directory.
Found 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.
- Vorherrschende Sprache
- JavaScript
- Sterne
- 122k
- Forks
- 37.4k
- Ø Merge
- 4 T. 17 Std.
- Gemergte PRs (30 T.)
- 300
Entwicklungsumgebung
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus nodejs/node
-
`test-fs-cp-async-socket` / `test-fs-cp-sync-copy-socket-error` failure on Darwin (path length)Offenflaky-test test v26.x
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
nodejs/node#66324 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
doc
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 90/100
Maintainer antworten meist innerhalb von 1 Tag
-
doc
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 65/100
Maintainer antworten meist innerhalb von 1 Tag
-
build
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 88/100
nodejs/node#66076 · 2 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 84/100
nodejs/node#65994 · 2 Kommentare · 2 Reaktionen ·
Maintainer antworten meist innerhalb von 1 Tag
Ähnliche Issues
-
bug CI breakage triage needed
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
oppia/oppia#27517 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
draftomen enhancement size: S
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 75/100
andreagrandi/draftomen#761 ·
-
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 92/100
HarperFast/harper#2866 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 84/100
HarperFast/harper-pro#927 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 88/100
anthropics/skills#1897 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag