Skip to content

Commit f46fd2a

Browse files
committed
chore: add experimental warning
1 parent a44d2c2 commit f46fd2a

File tree

9 files changed

+38
-5
lines changed

9 files changed

+38
-5
lines changed

packages/next/src/build/next-config-ts/transpile-config.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { CompilerOptions } from 'typescript'
22
import type { Options as SWCOptions } from '@swc/core'
3+
import type { NextConfig } from '../../types'
34
import { readFile } from 'node:fs/promises'
45
import { join } from 'node:path'
56
import { deregisterHook, registerHook, requireFromString } from './require-hook'
@@ -48,7 +49,7 @@ export async function transpileConfig({
4849
}: {
4950
nextConfigPath: string
5051
cwd: string
51-
}) {
52+
}): Promise<NextConfig> {
5253
let hasRequire = false
5354
try {
5455
const { compilerOptions } = await lazilyGetTSConfig(cwd)

packages/next/src/server/config-schema.ts

+1
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ export const configSchema: zod.ZodType<NextConfig> = z.lazy(() =>
248248
excludeDefaultMomentLocales: z.boolean().optional(),
249249
experimental: z
250250
.strictObject({
251+
nextConfigTs: z.boolean().optional(),
251252
after: z.boolean().optional(),
252253
appDocumentPreloading: z.boolean().optional(),
253254
preloadEntriesOnStart: z.boolean().optional(),

packages/next/src/server/config-shared.ts

+5
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,10 @@ export interface ReactCompilerOptions {
200200
}
201201

202202
export interface ExperimentalConfig {
203+
/**
204+
* Enable next.config.ts, defaults to true
205+
*/
206+
nextConfigTs?: boolean
203207
flyingShuttle?: boolean
204208
prerenderEarlyExit?: boolean
205209
linkNoTouchStart?: boolean
@@ -991,6 +995,7 @@ export const defaultConfig: NextConfig = {
991995
reactCompiler: undefined,
992996
after: false,
993997
staticGenerationRetryCount: undefined,
998+
nextConfigTs: true,
994999
},
9951000
bundlePagesRouterDependencies: false,
9961001
}

packages/next/src/server/config.ts

+10-3
Original file line numberDiff line numberDiff line change
@@ -969,9 +969,6 @@ export default async function loadConfig(
969969
nextConfigPath: path,
970970
cwd: dir,
971971
})
972-
curLog.warn(
973-
`Configuration with ${configFileName} is currently an experimental feature, use with caution.`
974-
)
975972
} else {
976973
userConfigModule = await import(pathToFileURL(path).href)
977974
}
@@ -1034,6 +1031,16 @@ export default async function loadConfig(
10341031
}
10351032
}
10361033

1034+
if (
1035+
configFileName === 'next.config.ts' &&
1036+
!userConfig.experimental?.nextConfigTs
1037+
) {
1038+
// warn when using next.config.ts but experimental.nextConfigTs is set to false
1039+
curLog.warn(
1040+
`Configuration with ${configFileName} is currently an experimental feature, use with caution.`
1041+
)
1042+
}
1043+
10371044
if (userConfig.target && userConfig.target !== 'server') {
10381045
throw new Error(
10391046
`The "target" property is no longer supported in ${configFileName}.\n` +
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { nextTestSetup } from 'e2e-utils'
2+
import { check } from 'next-test-utils'
3+
4+
describe('next-config-ts - experimental-warning', () => {
5+
const { next } = nextTestSetup({
6+
files: __dirname,
7+
})
8+
9+
it('should warn if experimental.nextConfigTs is set to false', async () => {
10+
await check(
11+
async () => next.cliOutput,
12+
/is currently an experimental feature, use with caution/i
13+
)
14+
})
15+
})

test/development/app-dir/hmr-next-config-ts/index.test.ts renamed to test/development/app-dir/next-config-ts/hmr.test.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { nextTestSetup } from 'e2e-utils'
22
import { check } from 'next-test-utils'
33

4-
describe('hmr-next-config-ts', () => {
4+
describe('next-config-ts - hmr', () => {
55
const { next } = nextTestSetup({
66
files: __dirname,
77
})
8+
89
it('should output config file change', async () => {
910
await check(async () => next.cliOutput, /ready/i)
1011

test/development/app-dir/hmr-next-config-ts/next.config.ts renamed to test/development/app-dir/next-config-ts/next.config.ts

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import type { NextConfig } from 'next'
22

33
const nextConfig = {
4+
experimental: {
5+
nextConfigTs: false,
6+
},
47
// target
58
} satisfies NextConfig
69

0 commit comments

Comments
 (0)