Skip to content

Commit 0d266e6

Browse files
authored
Port TS PR 61082 (Fix accidental ESM-mode directory module lookup in package non-root) (#1263)
1 parent 5795354 commit 0d266e6

File tree

3 files changed

+27
-31
lines changed

3 files changed

+27
-31
lines changed

internal/module/resolver.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -861,7 +861,7 @@ func (r *resolutionState) loadModuleFromSpecificNodeModulesDirectory(ext extensi
861861
return fromDirectory
862862
}
863863
// !!! this is ported exactly, but checking for null seems wrong?
864-
if packageInfo.Exists() &&
864+
if rest == "" && packageInfo.Exists() &&
865865
(packageInfo.Contents.Exports.Type == packagejson.JSONValueTypeNotPresent || packageInfo.Contents.Exports.Type == packagejson.JSONValueTypeNull) &&
866866
r.esmMode {
867867
// EsmMode disables index lookup in `loadNodeModuleFromDirectoryWorker` generally, however non-relative package resolutions still assume
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/index.ts(2,8): error TS2307: Cannot find module 'i-have-a-dir-and-main/dist/dir' or its corresponding type declarations.
2+
3+
4+
==== /node_modules/i-have-a-dir-and-main/package.json (0 errors) ====
5+
{
6+
"name": "i-have-a-dir-and-main",
7+
"version": "1.0.0",
8+
"type": "module",
9+
"main": "dist/index.js"
10+
}
11+
12+
==== /node_modules/i-have-a-dir-and-main/dist/index.d.ts (0 errors) ====
13+
export declare const a = 1;
14+
15+
==== /node_modules/i-have-a-dir-and-main/dist/dir/index.d.ts (0 errors) ====
16+
export declare const b = 2;
17+
18+
==== /package.json (0 errors) ====
19+
{ "type": "module" }
20+
21+
==== /index.ts (1 errors) ====
22+
import 'i-have-a-dir-and-main' // ok
23+
import 'i-have-a-dir-and-main/dist/dir' // error
24+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
25+
!!! error TS2307: Cannot find module 'i-have-a-dir-and-main/dist/dir' or its corresponding type declarations.
26+

testdata/baselines/reference/submodule/conformance/nodeModulesNoDirectoryModule.errors.txt.diff

Lines changed: 0 additions & 30 deletions
This file was deleted.

0 commit comments

Comments
 (0)