fix(javascript): resolve package exports targets only to the exact file (#1181)
A selected package exports target names one file, and Node tries no extension or directory index for it. REA still resolved it like a relative specifier, so `exports: "./file"` with only `file.js` present, or `"./folder"` with only `folder/index.js`, reported a resolved import that Node rejects under both import and require. Resolve an exports target only to its exact file and otherwise report not-found with a limitation naming the target. Legacy main entries keep their extension and index fallbacks. Fixes #1174 Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
e1afbc1914
commit
2a620c06cd
@@ -51,6 +51,18 @@ const cases: readonly {
|
||||
nodeError: "ERR_INVALID_PACKAGE_TARGET",
|
||||
rejectedTarget: "./../outside.cjs",
|
||||
},
|
||||
{
|
||||
name: "extensionless target is not completed with an extension",
|
||||
exports: "./actual",
|
||||
expected: null,
|
||||
nodeError: "MODULE_NOT_FOUND",
|
||||
},
|
||||
{
|
||||
// Node reports ERR_UNSUPPORTED_DIR_IMPORT for import, MODULE_NOT_FOUND for require.
|
||||
name: "directory target does not load its index",
|
||||
exports: "./folder",
|
||||
expected: null,
|
||||
},
|
||||
{
|
||||
name: "top-level array skips an invalid target",
|
||||
exports: ["./../outside.cjs", "./actual.cjs"],
|
||||
@@ -166,6 +178,7 @@ it.each(
|
||||
"node_modules/fixture/node_modules/actual.cjs",
|
||||
"node_modules/fixture/node_modules.cjs",
|
||||
"node_modules/fixture/literal%2e.cjs",
|
||||
"node_modules/fixture/folder/index.js",
|
||||
].map((path) => [path, `module.exports = ${JSON.stringify(path)};`]),
|
||||
),
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user