-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Fix index fallback of CJS package from ESM-mode import when main
is present but does not resolve
#49327
Merged
Merged
Fix index fallback of CJS package from ESM-mode import when main
is present but does not resolve
#49327
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
tests/baselines/reference/nodeNextImportModeImplicitIndexResolution2.errors.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/index.cts(4,21): error TS2307: Cannot find module 'dedent4' or its corresponding type declarations. | ||
/index.mts(4,21): error TS2307: Cannot find module 'dedent4' or its corresponding type declarations. | ||
|
||
|
||
==== /node_modules/@types/dedent/package.json (0 errors) ==== | ||
{ "name": "@types/dedent", "version": "1.0.0", "main": "" } | ||
|
||
==== /node_modules/@types/dedent2/package.json (0 errors) ==== | ||
{ "name": "@types/dedent2", "version": "1.0.0", "main": "asdfasdfasdf" } | ||
|
||
==== /node_modules/@types/dedent3/package.json (0 errors) ==== | ||
{ "name": "@types/dedent3", "version": "1.0.0", "main": "asdfasdfasdf", "exports": null } | ||
|
||
==== /node_modules/@types/dedent4/package.json (0 errors) ==== | ||
{ "name": "@types/dedent4", "version": "1.0.0", "main": "asdfasdfasdf", "exports": "./asdfasdfasdf" } | ||
|
||
==== /node_modules/@types/dedent/index.d.ts (0 errors) ==== | ||
export {}; | ||
|
||
==== /node_modules/@types/dedent2/index.d.ts (0 errors) ==== | ||
export {}; | ||
|
||
==== /node_modules/@types/dedent3/index.d.ts (0 errors) ==== | ||
export {}; | ||
|
||
==== /node_modules/@types/dedent4/index.d.ts (0 errors) ==== | ||
export {}; | ||
|
||
==== /index.mts (1 errors) ==== | ||
import dedent from "dedent"; | ||
import dedent2 from "dedent2"; | ||
import dedent3 from "dedent3"; | ||
import dedent4 from "dedent4"; // Error | ||
~~~~~~~~~ | ||
!!! error TS2307: Cannot find module 'dedent4' or its corresponding type declarations. | ||
|
||
==== /index.cts (1 errors) ==== | ||
import dedent from "dedent"; | ||
import dedent2 from "dedent2"; | ||
import dedent3 from "dedent3"; | ||
import dedent4 from "dedent4"; // Error | ||
~~~~~~~~~ | ||
!!! error TS2307: Cannot find module 'dedent4' or its corresponding type declarations. | ||
|
44 changes: 44 additions & 0 deletions
44
tests/baselines/reference/nodeNextImportModeImplicitIndexResolution2.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
//// [tests/cases/compiler/nodeNextImportModeImplicitIndexResolution2.ts] //// | ||
|
||
//// [package.json] | ||
{ "name": "@types/dedent", "version": "1.0.0", "main": "" } | ||
|
||
//// [package.json] | ||
{ "name": "@types/dedent2", "version": "1.0.0", "main": "asdfasdfasdf" } | ||
|
||
//// [package.json] | ||
{ "name": "@types/dedent3", "version": "1.0.0", "main": "asdfasdfasdf", "exports": null } | ||
|
||
//// [package.json] | ||
{ "name": "@types/dedent4", "version": "1.0.0", "main": "asdfasdfasdf", "exports": "./asdfasdfasdf" } | ||
|
||
//// [index.d.ts] | ||
export {}; | ||
|
||
//// [index.d.ts] | ||
export {}; | ||
|
||
//// [index.d.ts] | ||
export {}; | ||
|
||
//// [index.d.ts] | ||
export {}; | ||
|
||
//// [index.mts] | ||
import dedent from "dedent"; | ||
import dedent2 from "dedent2"; | ||
import dedent3 from "dedent3"; | ||
import dedent4 from "dedent4"; // Error | ||
|
||
//// [index.cts] | ||
import dedent from "dedent"; | ||
import dedent2 from "dedent2"; | ||
import dedent3 from "dedent3"; | ||
import dedent4 from "dedent4"; // Error | ||
|
||
|
||
//// [index.mjs] | ||
export {}; | ||
//// [index.cjs] | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); |
38 changes: 38 additions & 0 deletions
38
tests/baselines/reference/nodeNextImportModeImplicitIndexResolution2.symbols
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
=== /node_modules/@types/dedent/index.d.ts === | ||
export {}; | ||
No type information for this code. | ||
No type information for this code.=== /node_modules/@types/dedent2/index.d.ts === | ||
export {}; | ||
No type information for this code. | ||
No type information for this code.=== /node_modules/@types/dedent3/index.d.ts === | ||
export {}; | ||
No type information for this code. | ||
No type information for this code.=== /node_modules/@types/dedent4/index.d.ts === | ||
export {}; | ||
No type information for this code. | ||
No type information for this code.=== /index.mts === | ||
import dedent from "dedent"; | ||
>dedent : Symbol(dedent, Decl(index.mts, 0, 6)) | ||
|
||
import dedent2 from "dedent2"; | ||
>dedent2 : Symbol(dedent2, Decl(index.mts, 1, 6)) | ||
|
||
import dedent3 from "dedent3"; | ||
>dedent3 : Symbol(dedent3, Decl(index.mts, 2, 6)) | ||
|
||
import dedent4 from "dedent4"; // Error | ||
>dedent4 : Symbol(dedent4, Decl(index.mts, 3, 6)) | ||
|
||
=== /index.cts === | ||
import dedent from "dedent"; | ||
>dedent : Symbol(dedent, Decl(index.cts, 0, 6)) | ||
|
||
import dedent2 from "dedent2"; | ||
>dedent2 : Symbol(dedent2, Decl(index.cts, 1, 6)) | ||
|
||
import dedent3 from "dedent3"; | ||
>dedent3 : Symbol(dedent3, Decl(index.cts, 2, 6)) | ||
|
||
import dedent4 from "dedent4"; // Error | ||
>dedent4 : Symbol(dedent4, Decl(index.cts, 3, 6)) | ||
|
38 changes: 38 additions & 0 deletions
38
tests/baselines/reference/nodeNextImportModeImplicitIndexResolution2.types
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
=== /node_modules/@types/dedent/index.d.ts === | ||
export {}; | ||
No type information for this code. | ||
No type information for this code.=== /node_modules/@types/dedent2/index.d.ts === | ||
export {}; | ||
No type information for this code. | ||
No type information for this code.=== /node_modules/@types/dedent3/index.d.ts === | ||
export {}; | ||
No type information for this code. | ||
No type information for this code.=== /node_modules/@types/dedent4/index.d.ts === | ||
export {}; | ||
No type information for this code. | ||
No type information for this code.=== /index.mts === | ||
import dedent from "dedent"; | ||
>dedent : typeof dedent | ||
|
||
import dedent2 from "dedent2"; | ||
>dedent2 : typeof dedent2 | ||
|
||
import dedent3 from "dedent3"; | ||
>dedent3 : typeof dedent3 | ||
|
||
import dedent4 from "dedent4"; // Error | ||
>dedent4 : any | ||
|
||
=== /index.cts === | ||
import dedent from "dedent"; | ||
>dedent : typeof dedent | ||
|
||
import dedent2 from "dedent2"; | ||
>dedent2 : typeof dedent2 | ||
|
||
import dedent3 from "dedent3"; | ||
>dedent3 : typeof dedent3 | ||
|
||
import dedent4 from "dedent4"; // Error | ||
>dedent4 : any | ||
|
37 changes: 37 additions & 0 deletions
37
tests/cases/compiler/nodeNextImportModeImplicitIndexResolution2.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// @module: nodenext | ||
|
||
// @Filename: /node_modules/@types/dedent/package.json | ||
{ "name": "@types/dedent", "version": "1.0.0", "main": "" } | ||
|
||
// @Filename: /node_modules/@types/dedent2/package.json | ||
{ "name": "@types/dedent2", "version": "1.0.0", "main": "asdfasdfasdf" } | ||
|
||
// @Filename: /node_modules/@types/dedent3/package.json | ||
{ "name": "@types/dedent3", "version": "1.0.0", "main": "asdfasdfasdf", "exports": null } | ||
|
||
// @Filename: /node_modules/@types/dedent4/package.json | ||
{ "name": "@types/dedent4", "version": "1.0.0", "main": "asdfasdfasdf", "exports": "./asdfasdfasdf" } | ||
|
||
// @Filename: /node_modules/@types/dedent/index.d.ts | ||
export {}; | ||
|
||
// @Filename: /node_modules/@types/dedent2/index.d.ts | ||
export {}; | ||
|
||
// @Filename: /node_modules/@types/dedent3/index.d.ts | ||
export {}; | ||
|
||
// @Filename: /node_modules/@types/dedent4/index.d.ts | ||
export {}; | ||
|
||
// @Filename: /index.mts | ||
import dedent from "dedent"; | ||
import dedent2 from "dedent2"; | ||
import dedent3 from "dedent3"; | ||
import dedent4 from "dedent4"; // Error | ||
|
||
// @Filename: /index.cts | ||
import dedent from "dedent"; | ||
import dedent2 from "dedent2"; | ||
import dedent3 from "dedent3"; | ||
import dedent4 from "dedent4"; // Error |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Double checking on https://nodejs.org/api/esm.html#resolution-algorithm, recognizing both null and undefined here for
exports
seems good (only one usage makes that explicit, but it should be fine), however ignoringmain
and looking up an index regardless is not whatPACKAGE_RESOLVE
describes for anexport
less package... it just saysReturn the URL resolution of packageSubpath in packageURL.
, which doesn't imply any fallback toindex.js
lookup if themain
fails. If in practice it is, the algorithm in thenode
docs may be wrong. (Which doesn't surprise me, if I'm honest, I think the people writing the code are more pragmatic than the people reviewing/writing the docs.)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, there's a large legacy main resolution code block which isn't included in the documented algorithm.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've opened nodejs/node#43269 for the docs issue on node.