Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
andrewbranch merged 4 commits intomicrosoft:mainfromandrewbranch:feature/node20
Jun 9, 2025
Merged

Conversation

@andrewbranch
Copy link
Member

@andrewbranchandrewbranch commentedJun 2, 2025
edited
Loading

Following up on:

Also fixes:

This PR adds--module node20 as an alias fornodenext, the only difference beingnode20 implies--target es2023 whilenodenext implies--target esnext. It also adds tonode20/nodenext support fornodejs/node#54563:

// esm-lib:exportdefaultclassFoo{}export{Fooas"module.exports"};// CommonJS consumer:constFoo=require("esm-lib");// class Foo {}

Before this PR, TypeScript thought the type ofconst Foo was{ default: Foo, "module.exports": Foo }.

This PR also makesnode20 andnodenext implyresolveJsonModule. This change will be backported tonode16 andnode18 in TypeScript 6.0.

The new Node.js module option table looks like:

targetmoduleResolutionresolveJsonModuleimport assertionsimport attributesJSON importsrequire(esm)
node16es2022node16falseno restrictions
node18es2022node16falseneedstype "json"
node20es2023node16trueneedstype "json"
nodenextesnextnodenexttrueneedstype "json"

As a reminder, the semantics of--module node20 will only change if Node.js backports new module behavior into Node.js v20 (seems unlikely at this point), whereasnodenext is a moving target that will change as soon as Node.js introduces any new module behavior into the latest version of Node.js.

New baselines were validated againstnode18 andnodenext with

for f in tests/baselines/reference/*module=node20*; do  [[ -e ${f/module=node20/module=node18} ]] && echo "$f" && diff "$f" "${f/module=node20/module=node18}";done

and

for f in tests/baselines/reference/*module=node20*; do  [[ -e ${f/module=node20/module=nodenext} ]] && echo "$f" && diff "$f" "${f/module=node20/module=nodenext}";done

The latter produces only diffs related to the changingtarget setting or options diagnostics that quote the value of themodule option verbatim.

CopilotAI review requested due to automatic review settingsJune 2, 2025 16:28
@github-project-automationgithub-project-automationbot moved this toNot started inPR BacklogJun 2, 2025
@typescript-bottypescript-bot added Author: Team For Uncommitted BugPR for untriaged, rejected, closed or missing bug labelsJun 2, 2025
@typescript-bot
Copy link
Collaborator

Thanks for the PR! It looks like you've changed the TSServer protocol in some way. Please ensure that any changes here don't break consumers of the current TSServer API. For some extra review, we'll ping@sheetalkamat,@mjbvz,@zkat, and@joj for you. Feel free to loop in other consumers/maintainers if necessary.

Copy link
Contributor

CopilotAI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Pull Request Overview

This PR introduces a new module alias “--module node20,” which behaves similarly to “nodenext” but implies a target of ES2023 rather than ESNext. The changes include updates to diagnostics, compiler option computations, module resolution and transformation, as well as adjustments throughout the test baselines to support the new Node20 module option.

  • Updated test baselines to include “node20” in error messages.
  • Extended import fixes, module option computations, and type checker logic to recognize and handle Node20.
  • Updated enums, diagnostic messages, and command line parsing accordingly.

Reviewed Changes

Copilot reviewed 523 out of 523 changed files in this pull request and generated no comments.

FileDescription
tests/baselines/reference/*Revised error baseline files to include “node20” in allowed module option lists.
src/services/codefixes/importFixes.ts, fixModuleAndTargetOptions.tsAdded support for Node20 in import resolution and option fixers.
src/server/protocol.tsAdded Node20 to the ModuleKind enum.
src/compiler/**/*Updated utilities, types, transformers, checkers, and diagnostic messages to support the Node20 module option.

@typescript-bot
Copy link
Collaborator

Looks like you're introducing a change to the public API surface area. If this includes breaking changes, please document themon our wiki's API Breaking Changes page.

Also, please make sure@DanielRosenwasser and@RyanCavanaugh are aware of the changes, just as a heads up.

Copy link
Contributor

CopilotAI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Pull Request Overview

This PR introduces the --module node20 alias as an alternative to nodenext with a different target (ES2023 instead of ESNext) and updates all related diagnostics, error messages, and code paths accordingly.

  • Updates diagnostic messages, tests baselines, and compiler code to include node20 in the valid module list.
  • Adjusts module resolution, import fixes, and targeted emit options to account for node20.

Reviewed Changes

Copilot reviewed 523 out of 523 changed files in this pull request and generated 2 comments.

FileDescription
tests/baselines/reference/*Updates expected error messages to list node20 where applicable.
src/services/codefixes/*Adjusts code fixes so that node20 is treated alongside node16/node18/nodeNext.
src/compiler/*Updates various compiler routines and diagnostic messages to support node20.
src/server/protocol.tsAdds node20 into the ModuleKind enum for protocol communication.

dtchdanley-dev reacted with thumbs up emoji
@Mateusnasciment
Copy link

Does --module node20 fully replace nodenext for projects targeting Node.js 20, or are there still scenarios where nodenext would be preferred?

@andrewbranch
Copy link
MemberAuthor

They’re the same right now except for impliedtarget, but my usually recommendation is that library authors should use the pinnedmodule setting for the lowest version of Node.js they’re trying to support, while app developers keeping their app’s runtime environment more or less up to date with new Node.js releases can just usenodenext.

"Explicitly specified module resolution kind: 'NodeNext'.",
"Resolving in CJS mode with conditions 'require', 'types', 'node'.",
"Loading module as file / folder, candidate module location '/lib', target file types: TypeScript, JavaScript, Declaration.",
"Loading module as file / folder, candidate module location '/lib', target file types: TypeScript, JavaScript, Declaration, JSON.",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I was going to ask "what happens iflib.json exists", but I can see from the trace below thatlib.json is still not being checked, which is good. Phew.

andrewbranch reacted with thumbs up emoji
@github-project-automationgithub-project-automationbot moved this fromNot started toNeeds merge inPR BacklogJun 5, 2025
@andrewbranchandrewbranch merged commitcb38d99 intomicrosoft:mainJun 9, 2025
32 checks passed
@github-project-automationgithub-project-automationbot moved this fromNeeds merge toDone inPR BacklogJun 9, 2025
@andrewbranchandrewbranch deleted the feature/node20 branchJune 9, 2025 21:20
bjohn465 added a commit to bjohn465/republia-times that referenced this pull requestJul 31, 2025
From the TypeScript 5.9 release candidate blog post[1]:> TypeScript provides several `node*` options for the `--module` and> `--moduleResolution` settings. Most recently, `--module nodenext` has> supported the ability to `require()` ECMAScript modules from CommonJS> modules, and correctly rejects import assertions (in favor of the> standards-bound import attributes[2]).> TypeScript 5.9 brings a stable option for these settings called> `node20`, intended to model the behavior of Node.js v20. This option> is unlikely to have new behaviors in the future, unlike> `--module nodenext` or `--moduleResolution nodenext`. Also unlike> `nodenext`, specifying `--module node20` will imply `--target es2023`> unless otherwise configured. `--module nodenext`, on the other hand,> implies the floating `--target esnext`.> For more information, take a look at the implementation here[3].[1]:https://devblogs.microsoft.com/typescript/announcing-typescript-5-9-rc/#support-for---module-node20[2]:https://github.com/tc39/proposal-import-attributes[3]:microsoft/TypeScript#61805
RobinTail added a commit to RobinTail/express-zod-api that referenced this pull requestOct 4, 2025
`module: node20` introduced in Typescript 5.9 as a stable replacementfor `nodenext`:https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-9.html#support-for---module-node20The recommended combination is with `moduleResolution: node16`:microsoft/TypeScript#61805That change implies relative imports to have extensions, however, it'spossible to change them directly to `.ts`, which will also reiterate andresolve#2289 . It will enable running typescript natively by Node.jswithout `tsx`. It may also come handy if I decide to publish to JSR.<!-- This is an auto-generated comment: release notes by coderabbit.ai-->## Summary by CodeRabbit- Chores- Project build and compiler settings standardized; JSON imports madeexplicit and some tooling switched to static JSON imports.- Refactor- Internal module references normalized to explicit TypeScript entries;some runtime identifiers now derive from environment-provided buildmetadata.- Tests- Test imports updated for explicit module resolution; migration testsexpanded with additional valid cases.- Style- New lint rules encourage .ts extensions for local imports anddiscourage direct package.json imports.<!-- end of auto-generated comment: release notes by coderabbit.ai -->
zckrs added a commit to radiofrance/tsconfig that referenced this pull requestOct 31, 2025
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

Copilot code reviewCopilotCopilot left review comments

@jakebaileyjakebaileyjakebailey approved these changes

@weswighamweswighamAwaiting requested review from weswigham

Assignees

@andrewbranchandrewbranch

Labels

Author: TeamFor Uncommitted BugPR for untriaged, rejected, closed or missing bug

Projects

Status: Done

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

4 participants

@andrewbranch@typescript-bot@Mateusnasciment@jakebailey

[8]ページ先頭

©2009-2025 Movatter.jp