mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-04 03:09:39 -06:00
Fix accidental ESM-mode directory module lookup in package non-root (#61082)
This commit is contained in:
parent
0652664e64
commit
019fec8bf2
@ -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
|
||||
|
||||
@ -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.
|
||||
|
||||
26
tests/cases/conformance/node/nodeModulesNoDirectoryModule.ts
Normal file
26
tests/cases/conformance/node/nodeModulesNoDirectoryModule.ts
Normal 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
|
||||
Loading…
x
Reference in New Issue
Block a user