Fix accidental ESM-mode directory module lookup in package non-root (#61082)

This commit is contained in:
Andrew Branch 2025-01-30 10:17:14 -08:00 committed by GitHub
parent 0652664e64
commit 019fec8bf2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 53 additions and 1 deletions

View File

@ -3118,7 +3118,7 @@ function loadModuleFromSpecificNodeModulesDirectory(extensions: Extensions, modu
packageInfo,
);
if (
!pathAndExtension && packageInfo
!pathAndExtension && !rest && packageInfo
// eslint-disable-next-line no-restricted-syntax
&& (packageInfo.contents.packageJsonContent.exports === undefined || packageInfo.contents.packageJsonContent.exports === null)
&& state.features & NodeResolutionFeatures.EsmMode

View File

@ -0,0 +1,26 @@
/index.ts(2,8): error TS2307: Cannot find module 'i-have-a-dir-and-main/dist/dir' or its corresponding type declarations.
==== /node_modules/i-have-a-dir-and-main/package.json (0 errors) ====
{
"name": "i-have-a-dir-and-main",
"version": "1.0.0",
"type": "module",
"main": "dist/index.js"
}
==== /node_modules/i-have-a-dir-and-main/dist/index.d.ts (0 errors) ====
export declare const a = 1;
==== /node_modules/i-have-a-dir-and-main/dist/dir/index.d.ts (0 errors) ====
export declare const b = 2;
==== /package.json (0 errors) ====
{ "type": "module" }
==== /index.ts (1 errors) ====
import 'i-have-a-dir-and-main' // ok
import 'i-have-a-dir-and-main/dist/dir' // error
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2307: Cannot find module 'i-have-a-dir-and-main/dist/dir' or its corresponding type declarations.

View File

@ -0,0 +1,26 @@
// @noUncheckedSideEffectImports: true
// @strict: true
// @module: node16
// @noEmit: true
// @noTypesAndSymbols: true
// @Filename: /node_modules/i-have-a-dir-and-main/package.json
{
"name": "i-have-a-dir-and-main",
"version": "1.0.0",
"type": "module",
"main": "dist/index.js"
}
// @Filename: /node_modules/i-have-a-dir-and-main/dist/index.d.ts
export declare const a = 1;
// @Filename: /node_modules/i-have-a-dir-and-main/dist/dir/index.d.ts
export declare const b = 2;
// @Filename: /package.json
{ "type": "module" }
// @Filename: /index.ts
import 'i-have-a-dir-and-main' // ok
import 'i-have-a-dir-and-main/dist/dir' // error