Skip to content

Commit 019fec8

Browse files
authored
Fix accidental ESM-mode directory module lookup in package non-root (microsoft#61082)
1 parent 0652664 commit 019fec8

File tree

3 files changed

+53
-1
lines changed

3 files changed

+53
-1
lines changed

src/compiler/moduleNameResolver.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3118,7 +3118,7 @@ function loadModuleFromSpecificNodeModulesDirectory(extensions: Extensions, modu
31183118
packageInfo,
31193119
);
31203120
if (
3121-
!pathAndExtension && packageInfo
3121+
!pathAndExtension && !rest && packageInfo
31223122
// eslint-disable-next-line no-restricted-syntax
31233123
&& (packageInfo.contents.packageJsonContent.exports === undefined || packageInfo.contents.packageJsonContent.exports === null)
31243124
&& state.features & NodeResolutionFeatures.EsmMode
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+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// @noUncheckedSideEffectImports: true
2+
// @strict: true
3+
// @module: node16
4+
// @noEmit: true
5+
// @noTypesAndSymbols: true
6+
7+
// @Filename: /node_modules/i-have-a-dir-and-main/package.json
8+
{
9+
"name": "i-have-a-dir-and-main",
10+
"version": "1.0.0",
11+
"type": "module",
12+
"main": "dist/index.js"
13+
}
14+
15+
// @Filename: /node_modules/i-have-a-dir-and-main/dist/index.d.ts
16+
export declare const a = 1;
17+
18+
// @Filename: /node_modules/i-have-a-dir-and-main/dist/dir/index.d.ts
19+
export declare const b = 2;
20+
21+
// @Filename: /package.json
22+
{ "type": "module" }
23+
24+
// @Filename: /index.ts
25+
import 'i-have-a-dir-and-main' // ok
26+
import 'i-have-a-dir-and-main/dist/dir' // error

0 commit comments

Comments
 (0)