Repository navigation
Add --module node20
#61805
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
Andrew Branch (andrewbranch)
merged 4 commits into
microsoft:main
from
andrewbranch:feature/node20
Jun 9, 2025
Merged
Add --module node20
#61805
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
Support ESM
module.exports named exports
- Loading branch information
commit 218d141a0e38316e0dfc831b9e3bdd780ff74554
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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,24 @@ | ||
| /importer-cts.cts(10,10): error TS2614: Module '"./exporter.mjs"' has no exported member 'Oops'. Did you mean to use 'import Oops from "./exporter.mjs"' instead? | ||
|
|
||
|
|
||
| ==== /importer-cjs.cjs (0 errors) ==== | ||
| const Foo = require("./exporter.mjs"); | ||
| new Foo(); | ||
|
|
||
| ==== /importer-cts.cts (1 errors) ==== | ||
| import Foo = require("./exporter.mjs"); | ||
| new Foo(); | ||
|
|
||
| import Foo2 from "./exporter.mjs"; | ||
| new Foo2(); | ||
|
|
||
| import * as Foo3 from "./exporter.mjs"; | ||
| new Foo3(); | ||
|
|
||
| import { Oops } from "./exporter.mjs"; | ||
| ~~~~ | ||
| !!! error TS2614: Module '"./exporter.mjs"' has no exported member 'Oops'. Did you mean to use 'import Oops from "./exporter.mjs"' instead? | ||
|
|
||
| ==== /exporter.mts (0 errors) ==== | ||
| export default class Foo {} | ||
| export { Foo as "module.exports" }; |
This file contains hidden or 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,41 @@ | ||
| //// [tests/cases/conformance/node/esmModuleExports1.ts] //// | ||
|
|
||
| === /importer-cjs.cjs === | ||
| const Foo = require("./exporter.mjs"); | ||
| >Foo : Symbol(Foo, Decl(importer-cjs.cjs, 0, 5)) | ||
| >require : Symbol(require) | ||
| >"./exporter.mjs" : Symbol("/exporter", Decl(exporter.mts, 0, 0)) | ||
|
|
||
| new Foo(); | ||
| >Foo : Symbol(Foo, Decl(importer-cjs.cjs, 0, 5)) | ||
|
|
||
| === /importer-cts.cts === | ||
| import Foo = require("./exporter.mjs"); | ||
| >Foo : Symbol(Foo, Decl(importer-cts.cts, 0, 0)) | ||
|
|
||
| new Foo(); | ||
| >Foo : Symbol(Foo, Decl(importer-cts.cts, 0, 0)) | ||
|
|
||
| import Foo2 from "./exporter.mjs"; | ||
| >Foo2 : Symbol(Foo2, Decl(importer-cts.cts, 3, 6)) | ||
|
|
||
| new Foo2(); | ||
| >Foo2 : Symbol(Foo2, Decl(importer-cts.cts, 3, 6)) | ||
|
|
||
| import * as Foo3 from "./exporter.mjs"; | ||
| >Foo3 : Symbol(Foo3, Decl(importer-cts.cts, 6, 6)) | ||
|
|
||
| new Foo3(); | ||
| >Foo3 : Symbol(Foo3, Decl(importer-cts.cts, 6, 6)) | ||
|
|
||
| import { Oops } from "./exporter.mjs"; | ||
| >Oops : Symbol(Oops, Decl(importer-cts.cts, 9, 8)) | ||
|
|
||
| === /exporter.mts === | ||
| export default class Foo {} | ||
| >Foo : Symbol(Foo, Decl(exporter.mts, 0, 0)) | ||
|
|
||
| export { Foo as "module.exports" }; | ||
| >Foo : Symbol(Foo, Decl(exporter.mts, 0, 0)) | ||
| >"module.exports" : Symbol("module.exports", Decl(exporter.mts, 1, 8)) | ||
|
|
This file contains hidden or 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,65 @@ | ||
| //// [tests/cases/conformance/node/esmModuleExports1.ts] //// | ||
|
|
||
| === /importer-cjs.cjs === | ||
| const Foo = require("./exporter.mjs"); | ||
| >Foo : typeof Foo | ||
| > : ^^^^^^^^^^ | ||
| >require("./exporter.mjs") : typeof import("/exporter", { with: { "resolution-mode": "import" } }) | ||
| > : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| >require : any | ||
| > : ^^^ | ||
| >"./exporter.mjs" : "./exporter.mjs" | ||
| > : ^^^^^^^^^^^^^^^^ | ||
|
|
||
| new Foo(); | ||
| >new Foo() : Foo | ||
| > : ^^^ | ||
| >Foo : typeof Foo | ||
| > : ^^^^^^^^^^ | ||
|
|
||
| === /importer-cts.cts === | ||
| import Foo = require("./exporter.mjs"); | ||
| >Foo : typeof Foo | ||
| > : ^^^^^^^^^^ | ||
|
|
||
| new Foo(); | ||
| >new Foo() : Foo | ||
| > : ^^^ | ||
| >Foo : typeof Foo | ||
| > : ^^^^^^^^^^ | ||
|
|
||
| import Foo2 from "./exporter.mjs"; | ||
| >Foo2 : typeof Foo | ||
| > : ^^^^^^^^^^ | ||
|
|
||
| new Foo2(); | ||
| >new Foo2() : Foo | ||
| > : ^^^ | ||
| >Foo2 : typeof Foo | ||
| > : ^^^^^^^^^^ | ||
|
|
||
| import * as Foo3 from "./exporter.mjs"; | ||
| >Foo3 : typeof Foo | ||
| > : ^^^^^^^^^^ | ||
|
|
||
| new Foo3(); | ||
| >new Foo3() : Foo | ||
| > : ^^^ | ||
| >Foo3 : typeof Foo | ||
| > : ^^^^^^^^^^ | ||
|
|
||
| import { Oops } from "./exporter.mjs"; | ||
| >Oops : any | ||
| > : ^^^ | ||
|
|
||
| === /exporter.mts === | ||
| export default class Foo {} | ||
| >Foo : Foo | ||
| > : ^^^ | ||
|
|
||
| export { Foo as "module.exports" }; | ||
| >Foo : typeof Foo | ||
| > : ^^^^^^^^^^ | ||
| >"module.exports" : typeof Foo | ||
| > : ^^^^^^^^^^ | ||
|
|
43 changes: 43 additions & 0 deletions
43
tests/baselines/reference/esmModuleExports2(esmoduleinterop=false).errors.txt
This file contains hidden or 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,43 @@ | ||
| /importer-cjs.cjs(2,5): error TS2351: This expression is not constructable. | ||
| Type 'String' has no construct signatures. | ||
| /importer-cts.cts(2,5): error TS2351: This expression is not constructable. | ||
| Type 'String' has no construct signatures. | ||
| /importer-cts.cts(4,8): error TS1259: Module '"/exporter"' can only be default-imported using the 'esModuleInterop' flag | ||
| /importer-cts.cts(8,5): error TS2351: This expression is not constructable. | ||
| Type 'String' has no construct signatures. | ||
| /importer-cts.cts(10,10): error TS2614: Module '"./exporter.mjs"' has no exported member 'Oops'. Did you mean to use 'import Oops from "./exporter.mjs"' instead? | ||
|
|
||
|
|
||
| ==== /importer-cjs.cjs (1 errors) ==== | ||
| const Foo = require("./exporter.mjs"); | ||
| new Foo(); | ||
| ~~~ | ||
| !!! error TS2351: This expression is not constructable. | ||
| !!! error TS2351: Type 'String' has no construct signatures. | ||
|
|
||
| ==== /importer-cts.cts (4 errors) ==== | ||
| import Foo = require("./exporter.mjs"); | ||
| new Foo(); | ||
| ~~~ | ||
| !!! error TS2351: This expression is not constructable. | ||
| !!! error TS2351: Type 'String' has no construct signatures. | ||
|
|
||
| import Foo2 from "./exporter.mjs"; | ||
| ~~~~ | ||
| !!! error TS1259: Module '"/exporter"' can only be default-imported using the 'esModuleInterop' flag | ||
| new Foo2(); | ||
|
|
||
| import * as Foo3 from "./exporter.mjs"; | ||
| new Foo3(); | ||
| ~~~~ | ||
| !!! error TS2351: This expression is not constructable. | ||
| !!! error TS2351: Type 'String' has no construct signatures. | ||
|
|
||
| import { Oops } from "./exporter.mjs"; | ||
| ~~~~ | ||
| !!! error TS2614: Module '"./exporter.mjs"' has no exported member 'Oops'. Did you mean to use 'import Oops from "./exporter.mjs"' instead? | ||
|
|
||
| ==== /exporter.mts (0 errors) ==== | ||
| export default class Foo {} | ||
| const oops = "oops"; | ||
| export { oops as "module.exports" }; |
44 changes: 44 additions & 0 deletions
44
tests/baselines/reference/esmModuleExports2(esmoduleinterop=false).symbols
This file contains hidden or 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/conformance/node/esmModuleExports2.ts] //// | ||
|
|
||
| === /importer-cjs.cjs === | ||
| const Foo = require("./exporter.mjs"); | ||
| >Foo : Symbol(Foo, Decl(importer-cjs.cjs, 0, 5)) | ||
| >require : Symbol(require) | ||
| >"./exporter.mjs" : Symbol("/exporter", Decl(exporter.mts, 0, 0)) | ||
|
|
||
| new Foo(); | ||
| >Foo : Symbol(Foo, Decl(importer-cjs.cjs, 0, 5)) | ||
|
|
||
| === /importer-cts.cts === | ||
| import Foo = require("./exporter.mjs"); | ||
| >Foo : Symbol(Foo, Decl(importer-cts.cts, 0, 0)) | ||
|
|
||
| new Foo(); | ||
| >Foo : Symbol(Foo, Decl(importer-cts.cts, 0, 0)) | ||
|
|
||
| import Foo2 from "./exporter.mjs"; | ||
| >Foo2 : Symbol(Foo2, Decl(importer-cts.cts, 3, 6)) | ||
|
|
||
| new Foo2(); | ||
| >Foo2 : Symbol(Foo2, Decl(importer-cts.cts, 3, 6)) | ||
|
|
||
| import * as Foo3 from "./exporter.mjs"; | ||
| >Foo3 : Symbol(Foo3, Decl(importer-cts.cts, 6, 6)) | ||
|
|
||
| new Foo3(); | ||
| >Foo3 : Symbol(Foo3, Decl(importer-cts.cts, 6, 6)) | ||
|
|
||
| import { Oops } from "./exporter.mjs"; | ||
| >Oops : Symbol(Oops, Decl(importer-cts.cts, 9, 8)) | ||
|
|
||
| === /exporter.mts === | ||
| export default class Foo {} | ||
| >Foo : Symbol(Foo, Decl(exporter.mts, 0, 0)) | ||
|
|
||
| const oops = "oops"; | ||
| >oops : Symbol(oops, Decl(exporter.mts, 1, 5)) | ||
|
|
||
| export { oops as "module.exports" }; | ||
| >oops : Symbol(oops, Decl(exporter.mts, 1, 5)) | ||
| >"module.exports" : Symbol("module.exports", Decl(exporter.mts, 2, 8)) | ||
|
|
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.