Files
next.js/test/e2e/app-dir/next-config-ts-native-mts/import-js-extensions-cjs/next.config.mts
3275034bc6 Allow next.config.mts for Node.js native TS resolver (#83556)
Following up on https://github.com/vercel/next.js/pull/83240

When using ESM syntax in `next.config.ts` on a CJS project, Node.js
first assumes it as CJS, then parses it into ESM again, giving a
warning:

```
(node:27529) [MODULE_TYPELESS_PACKAGE_JSON] Warning: Module type of file://.../next.config.ts is not specified and it doesn't parse as CommonJS.
Reparsing as ES module because module syntax was detected. This incurs a performance overhead.
To eliminate this warning, add "type": "module" to .../package.json.
```

Therefore, give users the option to use `next.config.mts` which Node.js
expects ESM syntax.

The tests are a copy of `next-config-ts-native-ts` and only renamed the
config to mts.

---------

Co-authored-by: Sebastian "Sebbie" Silbermann <[email protected]>
2025-09-16 12:25:49 +02:00

26 lines
615 B
TypeScript

import type { NextConfig } from 'next'
import cjs from './fixtures/cjs.cjs'
import mjs from './fixtures/mjs.mjs'
import * as cts from './fixtures/cts.cts'
import mts from './fixtures/mts.mts'
import ts from './fixtures/ts.ts'
import js from './fixtures/js-cjs.js'
// top-level await will only work in Native TS mode.
// This is to ensure that the test is running in Native TS mode.
await Promise.resolve()
const nextConfig: NextConfig = {
env: {
cjs,
mjs,
// Node.js native TS can't handle `export =` syntax.
cts: (cts as any).default,
mts,
ts,
js,
},
}
export default nextConfig