Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 24, 2025
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 internal/module/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -861,7 +861,7 @@ func (r *resolutionState) loadModuleFromSpecificNodeModulesDirectory(ext extensi
return fromDirectory
}
// !!! this is ported exactly, but checking for null seems wrong?
if packageInfo.Exists() &&
if rest == "" && packageInfo.Exists() &&
(packageInfo.Contents.Exports.Type == packagejson.JSONValueTypeNotPresent || packageInfo.Contents.Exports.Type == packagejson.JSONValueTypeNull) &&
r.esmMode {
// EsmMode disables index lookup in `loadNodeModuleFromDirectoryWorker` generally, however non-relative package resolutions still assume
Expand Down
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.

This file was deleted.