Bug Report
🔎 Search Terms
imports priority, exports priority, imports order, exports order, imports lookup, exports lookup, multi imports, multi exports
🕗 Version & Regression Information
- This changed between versions 4.5 and 4.7
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about Node12
⏯ Playground Link
Not applicable
💻 Code
Given file ./test/setup.ts, file ./src/lib/Service.ts, and ./package.json:
{
"imports": {
"#test/*": "./test/*.js",
"#lib/*": null,
"#*": "./src/*.js",
}
}
🙁 Actual behavior
TS can't find #test/setup, but can find #lib/Service. I debugged and found here, in loadModuleFromImportsOrExports,
|
const expandingKeys = sort(filter(getOwnKeys(lookupTable as MapLike<unknown>), k => k.indexOf("*") !== -1 || endsWith(k, "/")), (a, b) => a.length - b.length); |
|
for (const potentialTarget of expandingKeys) { |
TS sorts the expanding keys from short to long before the loop. So the first potentialTarget is #*, and it matches both, resolving to ./src/test/setup.ts and ./src/lib/Service.ts. It's very likely that it sorts in the reverse way.
🙂 Expected behavior
- For
#test/setup, TS tests #test/* first, and resolves to ./test/setup.ts.
- For
#lib/Service, TS tests #test/* first, not matched, then tests #lib/*, resolves to null, goes to the null branch in loadModuleFromTargetImportOrExport and returns undefined.
The same algorithm applies to exports field.
Bug Report
🔎 Search Terms
imports priority, exports priority, imports order, exports order, imports lookup, exports lookup, multi imports, multi exports
🕗 Version & Regression Information
⏯ Playground Link
Not applicable
💻 Code
Given file
./test/setup.ts, file./src/lib/Service.ts, and./package.json:{ "imports": { "#test/*": "./test/*.js", "#lib/*": null, "#*": "./src/*.js", } }🙁 Actual behavior
TS can't find
#test/setup, but can find#lib/Service. I debugged and found here, inloadModuleFromImportsOrExports,TypeScript/src/compiler/moduleNameResolver.ts
Lines 2074 to 2075 in 6cda20d
TS sorts the expanding keys from short to long before the loop. So the first
potentialTargetis#*, and it matches both, resolving to./src/test/setup.tsand./src/lib/Service.ts. It's very likely that it sorts in the reverse way.🙂 Expected behavior
#test/setup, TS tests#test/*first, and resolves to./test/setup.ts.#lib/Service, TS tests#test/*first, not matched, then tests#lib/*, resolves tonull, goes to thenullbranch inloadModuleFromTargetImportOrExportand returns undefined.The same algorithm applies to
exportsfield.