Skip to content

Commit 3c2fc61

Browse files
authored
Fix validateTurboNextConfig running for next start (#86886)
This fixes `validateTurboNextConfig` running during `next start` which was caught due to the wrong `phase` being provided to `workflows` config wrapper. We shouldn't run extra validation during `next start` as this needs to boot as fast as possible and would have already been validated during `next build` or `next dev`.
1 parent 3bb0bcb commit 3c2fc61

File tree

4 files changed

+13
-14
lines changed

4 files changed

+13
-14
lines changed

packages/next/src/build/turbopack-analyze/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { getSupportedBrowsers } from '../utils'
88
import { normalizePath } from '../../lib/normalize-path'
99
import type { NextConfigComplete } from '../../server/config-shared'
1010
import type { __ApiPreviewProps } from '../../server/api-utils'
11+
import { PHASE_PRODUCTION_BUILD } from '../../api/constants'
1112

1213
export type AnalyzeContext = {
1314
config: NextConfigComplete
@@ -25,7 +26,7 @@ export async function turbopackAnalyze(
2526
}> {
2627
await validateTurboNextConfig({
2728
dir: analyzeContext.dir,
28-
isDev: false,
29+
configPhase: PHASE_PRODUCTION_BUILD,
2930
})
3031

3132
const { config, dir, distDir, noMangling } = analyzeContext

packages/next/src/build/turbopack-build/impl.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export async function turbopackBuild(): Promise<{
2828
}> {
2929
await validateTurboNextConfig({
3030
dir: NextBuildContext.dir!,
31-
isDev: false,
31+
configPhase: PHASE_PRODUCTION_BUILD,
3232
})
3333

3434
const config = NextBuildContext.config!

packages/next/src/lib/turbopack-warning.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
import type { NextConfigComplete } from '../server/config-shared'
22
import loadConfig from '../server/config'
33
import * as Log from '../build/output/log'
4-
import {
5-
PHASE_DEVELOPMENT_SERVER,
6-
PHASE_PRODUCTION_BUILD,
7-
} from '../shared/lib/constants'
84

95
const unsupportedTurbopackNextConfigOptions = [
106
// Left to be implemented (priority)
@@ -45,10 +41,10 @@ const unsupportedTurbopackNextConfigOptions = [
4541
/** */
4642
export async function validateTurboNextConfig({
4743
dir,
48-
isDev,
44+
configPhase,
4945
}: {
5046
dir: string
51-
isDev?: boolean
47+
configPhase: Parameters<typeof loadConfig>[0]
5248
}) {
5349
const { defaultConfig } =
5450
require('../server/config-shared') as typeof import('../server/config-shared')
@@ -65,16 +61,15 @@ export async function validateTurboNextConfig({
6561
const unsupportedConfig: string[] = []
6662
let rawNextConfig: NextConfigComplete = {} as NextConfigComplete
6763

68-
const phase = isDev ? PHASE_DEVELOPMENT_SERVER : PHASE_PRODUCTION_BUILD
6964
try {
7065
rawNextConfig = interopDefault(
71-
await loadConfig(phase, dir, {
66+
await loadConfig(configPhase, dir, {
7267
rawConfig: true,
7368
})
7469
)
7570

7671
if (typeof rawNextConfig === 'function') {
77-
rawNextConfig = (rawNextConfig as any)(phase, {
72+
rawNextConfig = (rawNextConfig as any)(configPhase, {
7873
defaultConfig,
7974
})
8075
}

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ import setupDebug from 'next/dist/compiled/debug'
2525
import { RESTART_EXIT_CODE } from './utils'
2626
import { formatHostname } from './format-hostname'
2727
import { initialize } from './router-server'
28-
import { CONFIG_FILES } from '../../shared/lib/constants'
28+
import {
29+
CONFIG_FILES,
30+
PHASE_DEVELOPMENT_SERVER,
31+
} from '../../shared/lib/constants'
2932
import { getStartServerInfo, logStartInfo } from './app-info-log'
3033
import { validateTurboNextConfig } from '../../lib/turbopack-warning'
3134
import { type Span, trace, flushAllTraces } from '../../trace'
@@ -473,10 +476,10 @@ export async function startServer(
473476

474477
Log.event(`Ready in ${formatDurationText}`)
475478

476-
if (process.env.TURBOPACK) {
479+
if (process.env.TURBOPACK && isDev) {
477480
await validateTurboNextConfig({
478481
dir: serverOptions.dir,
479-
isDev: serverOptions.isDev,
482+
configPhase: PHASE_DEVELOPMENT_SERVER,
480483
})
481484
}
482485
} catch (err) {

0 commit comments

Comments
 (0)