You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Module resolution in `next.config.ts` is currently limited to CommonJS. However, ECMAScript Modules syntax is available when [using Node.js native TypeScript resolver](#using-nodejs-native-typescript-resolver-for-nextconfigts) for Node.js v22.10.0 and higher.
99
+
Module resolution in `next.config.ts` is currently limited to CommonJS. However, ECMAScript Modules (ESM) syntax is available when [using Node.js native TypeScript resolver](#using-nodejs-native-typescript-resolver-for-nextconfigts) for Node.js v22.10.0 and higher.
100
100
101
101
When using the `next.config.js` file, you can add some type checking in your IDE using JSDoc as below:
102
102
@@ -113,17 +113,17 @@ module.exports = nextConfig
113
113
114
114
### Using Node.js Native TypeScript Resolver for `next.config.ts`
115
115
116
-
> **Note**: Resolving `next.config.ts` using Node.js native TypeScript resolver is available for Node.js v22.10.0 and higher, and only when the feature is enabled. Next.js does not enable the feature by default.
116
+
> **Note**: Using Node.js native TypeScript resolver for `next.config.ts` is available for Node.js v22.10.0 and higher, and only when the feature is enabled. Next.js does not enable the feature by default.
117
117
118
-
Next.js feature detects [Node.js native TypeScript resolver](https://nodejs.org/api/typescript.html) by [`process.features.typescript`](https://nodejs.org/api/process.html#processfeaturestypescript) which was added in Node.js v22.10.0. This allows `next.config.ts` to use native ECMAScript Modules syntax like top-level `await` and dynamic imports in `next.config.ts`. However, it inherits the limitations of the Node.js native TypeScript resolver.
118
+
Next.js feature detects [Node.js native TypeScript resolver](https://nodejs.org/api/typescript.html) by [`process.features.typescript`](https://nodejs.org/api/process.html#processfeaturestypescript) which was added in Node.js v22.10.0. This allows `next.config.ts` to use native ECMAScript Modules (ESM) syntax like top-level `await` and dynamic imports in `next.config.ts`. However, it inherits the limitations of the Node.js native TypeScript resolver.
119
119
120
-
For Node.js below v23.6.0, you need to run `next dev` with `NODE_OPTIONS=--experimental-transform-types` flag to enable the Node.js native TypeScript resolver:
120
+
Node.js enables the feature by default since [v22.18.0](https://nodejs.org/en/blog/release/v22.18.0). For versions below v22.18.0, you need to run `next dev` with `NODE_OPTIONS=--experimental-transform-types` flag to enable the Node.js native TypeScript resolver:
121
121
122
122
```bash
123
123
NODE_OPTIONS=--experimental-transform-types next <command>
124
124
```
125
125
126
-
Although `next.config.ts` supports native ECMAScript Modules syntax on CommonJS projects, Node.js will still assume `next.config.ts` is a CommonJS file by default, resulting in Node.js reparsing the file as ECMAScript Modules when module syntax is detected. Therefore, we recommend using the `next.config.mts` file for CommonJS projects.
126
+
Although `next.config.ts` supports native ESM syntax on CommonJS projects, Node.js will still assume `next.config.ts` is a CommonJS file by default, resulting in Node.js reparsing the file as ESM when module syntax is detected. Therefore, we recommend using the `next.config.mts` file for CommonJS projects.
0 commit comments