Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/compiler/moduleNameResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 26 additions & 0 deletions tests/baselines/reference/nodeModulesNoDirectoryModule.errors.txt
Original file line number Diff line number Diff line change
@@ -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 changes: 26 additions & 0 deletions tests/cases/conformance/node/nodeModulesNoDirectoryModule.ts
Original file line number Diff line number Diff line change
@@ -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