Skip to content

Commit 73bdebb

Browse files
committed
2 parents e11e577 + e5652f4 commit 73bdebb

File tree

6 files changed

+27
-18
lines changed

6 files changed

+27
-18
lines changed

packages/documentation/copy/en/modules-reference/Reference.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ declare module "*.html" {
201201

202202
This section discusses the details of each `module` compiler option value. See the [_Module output format_](/docs/handbook/modules/theory.html#the-module-output-format) theory section for more background on what the option is and how it fits into the overall compilation process. In brief, the `module` compiler option was historically only used to control the output module format of emitted JavaScript files. The more recent `node16`, `node18`, and `nodenext` values, however, describe a wide range of characteristics of Node.js’s module system, including what module formats are supported, how the module format of each file is determined, and how different module formats interoperate.
203203

204-
### `node16`, `node18`, `nodenext`
204+
### `node16`, `node18`, `node20`, `nodenext`
205205

206206
Node.js supports both CommonJS and ECMAScript modules, with specific rules for which format each file can be and how the two formats are allowed to interoperate. `node16`, `node18`, and `nodenext` describe the full range of behavior for Node.js’s dual-format module system, and **emit files in either CommonJS or ESM format**. This is different from every other `module` option, which are runtime-agnostic and force all output files into a single format, leaving it to the user to ensure the output is valid for their runtime.
207207

@@ -1121,7 +1121,7 @@ import mod = require("./mod"); // `require` algorithm due to syntax (emit
11211121

11221122
#### Implied and enforced options
11231123

1124-
- `--moduleResolution node16` and `nodenext` must be paired with [`--module node16`, `node18`, or `nodenext`](#node16-node18-nodenext).
1124+
- `--moduleResolution node16` and `nodenext` must be paired with [`--module node16`, `node18`, `node20`, or `nodenext`](#node16-node18-node20-nodenext).
11251125

11261126
#### Supported features
11271127

packages/documentation/copy/en/modules-reference/Theory.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,16 +105,16 @@ The `module` compiler option provides this information to the compiler. Its prim
105105

106106
The available `module` settings are
107107

108-
- [**`node16`**](/docs/handbook/modules/reference.html#node16-node18-nodenext): Reflects the module system of Node.js v16+, which supports ES modules and CJS modules side-by-side with particular interoperability and detection rules.
109-
- [**`node18`**](/docs/handbook/modules/reference.html#node16-node18-nodenext): Reflects the module system of Node.js v18+, which adds support for import attributes.
110-
- [**`nodenext`**](/docs/handbook/modules/reference.html#node16-node18-nodenext): A moving target reflecting the latest Node.js versions as Node.js’s module system evolves. As of TypeScript 5.8, `nodenext` supports `require` of ECMAScript modules.
108+
- [**`node16`**](/docs/handbook/modules/reference.html#node16-node18-node20-nodenext): Reflects the module system of Node.js v16+, which supports ES modules and CJS modules side-by-side with particular interoperability and detection rules.
109+
- [**`node18`**](/docs/handbook/modules/reference.html#node16-node18-node20-nodenext): Reflects the module system of Node.js v18+, which adds support for import attributes.
110+
- [**`nodenext`**](/docs/handbook/modules/reference.html#node16-node18-node20-nodenext): A moving target reflecting the latest Node.js versions as Node.js’s module system evolves. As of TypeScript 5.8, `nodenext` supports `require` of ECMAScript modules.
111111
- [**`es2015`**](/docs/handbook/modules/reference.html#es2015-es2020-es2022-esnext): Reflects the ES2015 language specification for JavaScript modules (the version that first introduced `import` and `export` to the language).
112112
- [**`es2020`**](/docs/handbook/modules/reference.html#es2015-es2020-es2022-esnext): Adds support for `import.meta` and `export * as ns from "mod"` to `es2015`.
113113
- [**`es2022`**](/docs/handbook/modules/reference.html#es2015-es2020-es2022-esnext): Adds support for top-level `await` to `es2020`.
114114
- [**`esnext`**](/docs/handbook/modules/reference.html#es2015-es2020-es2022-esnext): Currently identical to `es2022`, but will be a moving target reflecting the latest ECMAScript specifications, as well as module-related Stage 3+ proposals that are expected to be included in upcoming specification versions.
115115
- **[`commonjs`](/docs/handbook/modules/reference.html#commonjs), [`system`](/docs/handbook/modules/reference.html#system), [`amd`](/docs/handbook/modules/reference.html#amd), and [`umd`](/docs/handbook/modules/reference.html#umd)**: Each emits everything in the module system named, and assumes everything can be successfully imported into that module system. These are no longer recommended for new projects and will not be covered in detail by this documentation.
116116

117-
> Node.js’s rules for module format detection and interoperability make it incorrect to specify `module` as `esnext` or `commonjs` for projects that run in Node.js, even if all files emitted by `tsc` are ESM or CJS, respectively. The only correct `module` settings for projects that intend to run in Node.js are `node16` and `nodenext`. While the emitted JavaScript for an all-ESM Node.js project might look identical between compilations using `esnext` and `nodenext`, the type checking can differ. See the [reference section on `nodenext`](/docs/handbook/modules/reference.html#node16-node18-nodenext) for more details.
117+
> Node.js’s rules for module format detection and interoperability make it incorrect to specify `module` as `esnext` or `commonjs` for projects that run in Node.js, even if all files emitted by `tsc` are ESM or CJS, respectively. The only correct `module` settings for projects that intend to run in Node.js are `node16` and `nodenext`. While the emitted JavaScript for an all-ESM Node.js project might look identical between compilations using `esnext` and `nodenext`, the type checking can differ. See the [reference section on `nodenext`](/docs/handbook/modules/reference.html#node16-node18-node20-nodenext) for more details.
118118
119119
### Module format detection
120120

packages/documentation/copy/en/project-config/Compiler Options.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -868,7 +868,7 @@ tsc app.ts util.ts --target esnext --outfile index.js
868868
<td><code><a href='/tsconfig/#moduleResolution'>--moduleResolution</a></code></td>
869869
<td><p><code>classic</code>, <code>node10</code>/<code>node</code>, <code>node16</code>, <code>nodenext</code>, or <code>bundler</code></p>
870870
</td>
871-
<td><p><code>Node10</code> if <a href="#module"><code>module</code></a> is <code>CommonJS</code>; <code>Node16</code> if <a href="#module"><code>module</code></a> is <code>Node16</code> or <code>Node18</code>; <code>NodeNext</code> if <a href="#module"><code>module</code></a> is <code>NodeNext</code>; <code>Bundler</code> if <a href="#module"><code>module</code></a> is <code>Preserve</code>; <code>Classic</code> otherwise.</p>
871+
<td><p><code>Node10</code> if <a href="#module"><code>module</code></a> is <code>CommonJS</code>; <code>Node16</code> if <a href="#module"><code>module</code></a> is <code>Node16</code>, <code>Node18</code>, or <code>Node20</code>; <code>NodeNext</code> if <a href="#module"><code>module</code></a> is <code>NodeNext</code>; <code>Bundler</code> if <a href="#module"><code>module</code></a> is <code>Preserve</code>; <code>Classic</code> otherwise.</p>
872872
</td>
873873
</tr>
874874
<tr class="option-description even"><td colspan="3">
@@ -1462,7 +1462,7 @@ tsc app.ts util.ts --target esnext --outfile index.js
14621462
<td><code><a href='/tsconfig/#target'>--target</a></code></td>
14631463
<td><p><code>es3</code>, <code>es5</code>, <code>es6</code>/<code>es2015</code>, <code>es2016</code>, <code>es2017</code>, <code>es2018</code>, <code>es2019</code>, <code>es2020</code>, <code>es2021</code>, <code>es2022</code>, <code>es2023</code>, <code>es2024</code>, or <code>esnext</code></p>
14641464
</td>
1465-
<td><p><code>ES5</code></p>
1465+
<td><p><code>es2023</code> if <a href="#module"><code>module</code></a> is <code>node20</code>; <code>esnext</code> if <a href="#module"><code>module</code></a> is <code>nodenext</code>; <code>ES5</code> otherwise.</p>
14661466
</td>
14671467
</tr>
14681468
<tr class="option-description even"><td colspan="3">

packages/tsconfig-reference/copy/en/options/module.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,14 @@ export const twoPi = valueOfPi * 2;
8787

8888
In addition to the base functionality of `ES2015`/`ES6`, `ES2020` adds support for [dynamic `import`s](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import), and [`import.meta`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import.meta) while `ES2022` further adds support for [top level `await`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/await#top_level_await).
8989

90-
#### `node16`/`node18`/`nodenext`
90+
#### `node16`/`node18`/`node20`/`nodenext`
9191

92-
The `node16`, `node18`, and `nodenext` modes integrate with Node's [native ECMAScript Module support](https://nodejs.org/api/esm.html). The emitted JavaScript uses either `CommonJS` or `ES2020` output depending on the file extension and the value of the `type` setting in the nearest `package.json`. Module resolution also works differently. You can learn more in the [handbook](/docs/handbook/esm-node.html) and [Modules Reference](/docs/handbook/modules/reference.html#node16-node18-nodenext).
92+
The `node16`, `node18`, `node20`, and `nodenext` modes integrate with Node's [native ECMAScript Module support](https://nodejs.org/api/esm.html). The emitted JavaScript uses either `CommonJS` or `ES2020` output depending on the file extension and the value of the `type` setting in the nearest `package.json`. Module resolution also works differently. You can learn more in the [handbook](/docs/handbook/esm-node.html) and [Modules Reference](/docs/handbook/modules/reference.html#node16-node18-node20-nodenext).
9393

9494
- `node16` is available from TypeScript 4.7
9595
- `node18` is available from TypeScript 5.8 as a replacement for `node16`, with added support for import attributes.
96-
- `nodenext` is available from TypeScript 4.7, but its behavior changes with the latest stable versions of Node.js. As of TypeScript 5.8, `nodenext` supports `require` of ECMAScript modules.
96+
- `node20` adds support for require(ESM).
97+
- `nodenext` is available from TypeScript 4.7, but its behavior changes with the latest stable versions of Node.js. `--module nodenext` implies the floating `--target esnext`.
9798

9899
#### `preserve`
99100

packages/tsconfig-reference/scripts/tsconfigRules.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ export const defaultsForOptions = {
239239
],
240240
moduleResolution: [
241241
"`Node10` if [`module`](#module) is `CommonJS`;",
242-
"`Node16` if [`module`](#module) is `Node16` or `Node18`;",
242+
"`Node16` if [`module`](#module) is `Node16`, `Node18`, or `Node20`;",
243243
"`NodeNext` if [`module`](#module) is `NodeNext`;",
244244
"`Bundler` if [`module`](#module) is `Preserve`;",
245245
"`Classic` otherwise.",
@@ -265,7 +265,11 @@ export const defaultsForOptions = {
265265
useUnknownInCatchVariables: trueIf("strict"),
266266
strictPropertyInitialization: trueIf("strict"),
267267
strictNullChecks: trueIf("strict"),
268-
target: "ES5",
268+
target: [
269+
"`es2023` if [`module`](#module) is `node20`;",
270+
"`esnext` if [`module`](#module) is `nodenext`;",
271+
"`ES5` otherwise.",
272+
],
269273
useDefineForClassFields: [
270274
"`true` if [`target`](#target) is `ES2022` or higher, including `ESNext`;",
271275
"`false` otherwise.",

packages/typescriptlang-org/src/redirects/setupRedirects.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,17 @@ export const setupRedirects = (
5151
addRedirects(veryOldRedirects)
5252
addRedirects(handbookRedirects)
5353
addRedirects({
54-
"/docs/handbook/esm-node": "/docs/handbook/modules/reference.html#node16-node18-nodenext",
55-
"/docs/handbook/esm-node.html": "/docs/handbook/modules/reference.html#node16-node18-nodenext",
54+
"/docs/handbook/esm-node":
55+
"/docs/handbook/modules/reference.html#node16-node18-node20-nodenext",
56+
"/docs/handbook/esm-node.html":
57+
"/docs/handbook/modules/reference.html#node16-node18-node20-nodenext",
5658
"/docs/handbook/modules": "/docs/handbook/modules/introduction.html",
5759
"/docs/handbook/modules.html": "/docs/handbook/modules/introduction.html",
58-
"/docs/handbook/module-resolution": "/docs/handbook/modules/theory.html#module-resolution",
59-
"/docs/handbook/module-resolution.html": "/docs/handbook/modules/theory.html#module-resolution",
60-
});
60+
"/docs/handbook/module-resolution":
61+
"/docs/handbook/modules/theory.html#module-resolution",
62+
"/docs/handbook/module-resolution.html":
63+
"/docs/handbook/modules/theory.html#module-resolution",
64+
})
6165
// These have been replaced by the real output in the handbook
6266
// addRedirects({
6367
// "/assets/typescript-handbook.epub": "/docs/handbook/intro.html",

0 commit comments

Comments
 (0)