Skip to content

Commit df30a24

Browse files
committed
[fix] only validate next config once
1 parent b94934e commit df30a24

File tree

4 files changed

+16
-4
lines changed

4 files changed

+16
-4
lines changed

packages/next/src/build/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -849,6 +849,7 @@ export default async function build(
849849
loadConfig(PHASE_PRODUCTION_BUILD, dir, {
850850
// Log for next.config loading process
851851
silent: false,
852+
validateConfig: true,
852853
reactProductionProfiling,
853854
}),
854855
turborepoAccessTraceResult

packages/next/src/cli/next-dev.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,10 @@ const nextDev = async (
219219
// some set-ups that rely on listening on other interfaces
220220
const host = options.hostname
221221

222-
config = await loadConfig(PHASE_DEVELOPMENT_SERVER, dir)
222+
config = await loadConfig(PHASE_DEVELOPMENT_SERVER, dir, {
223+
validateConfig: true,
224+
silent: false,
225+
})
223226

224227
if (
225228
options.experimentalUploadTrace &&

packages/next/src/server/config.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,12 +1156,14 @@ export default async function loadConfig(
11561156
customConfig,
11571157
rawConfig,
11581158
silent = true,
1159+
validateConfig,
11591160
onLoadUserConfig,
11601161
reactProductionProfiling,
11611162
}: {
11621163
customConfig?: object | null
11631164
rawConfig?: boolean
11641165
silent?: boolean
1166+
validateConfig?: boolean
11651167
onLoadUserConfig?: (conf: NextConfig) => void
11661168
reactProductionProfiling?: boolean
11671169
} = {}
@@ -1275,13 +1277,16 @@ export default async function loadConfig(
12751277
)),
12761278
} as NextConfig
12771279

1278-
if (!process.env.NEXT_MINIMAL) {
1280+
// Only validate the config against schema in:
1281+
// * non minimal mode
1282+
// * when `loadConfig` result is not silent
1283+
if (!process.env.NEXT_MINIMAL && validateConfig) {
12791284
// We only validate the config against schema in non minimal mode
12801285
const { configSchema } =
12811286
require('./config-schema') as typeof import('./config-schema')
12821287
const state = configSchema.safeParse(userConfig)
12831288

1284-
if (state.success === false) {
1289+
if (!state.success) {
12851290
// error message header
12861291
const messages = [`Invalid ${configFileName} options detected: `]
12871292

packages/next/src/server/lib/router-server.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,10 @@ export async function initialize(opts: {
100100
const config = await loadConfig(
101101
opts.dev ? PHASE_DEVELOPMENT_SERVER : PHASE_PRODUCTION_SERVER,
102102
opts.dir,
103-
{ silent: false }
103+
{
104+
silent: opts.dev,
105+
validateConfig: !opts.dev,
106+
}
104107
)
105108

106109
let compress: ReturnType<typeof setupCompression> | undefined

0 commit comments

Comments
 (0)