Skip to content

Commit a0f14d3

Browse files
committed
fix: prevent bundling of ZodError type
1 parent f70caa2 commit a0f14d3

File tree

2 files changed

+26
-38
lines changed

2 files changed

+26
-38
lines changed

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

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import { SubresourceIntegrityAlgorithm } from '../build/webpack/plugins/subresou
1010
import { WEB_VITALS } from '../shared/lib/utils'
1111
import type { NextParsedUrlQuery } from './request-meta'
1212
import { SizeLimit } from '../../types'
13-
import type { ZodError } from 'zod'
1413

1514
export type NextConfigComplete = Required<NextConfig> & {
1615
images: Required<ImageConfigComplete>
@@ -781,18 +780,3 @@ export async function normalizeConfig(phase: string, config: any) {
781780
// Support `new Promise` and `async () =>` as return values of the config export
782781
return await config
783782
}
784-
785-
export function validateConfig(userConfig: NextConfig): ZodError | null {
786-
if (process.env.NEXT_MINIMAL) {
787-
return null
788-
}
789-
790-
const { configSchema } =
791-
require('./config-schema') as typeof import('./config-schema')
792-
const state = configSchema.safeParse(userConfig)
793-
if (state.success) {
794-
return null
795-
}
796-
797-
return state.error
798-
}

packages/next/src/server/config.ts

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import {
99
normalizeConfig,
1010
ExperimentalConfig,
1111
NextConfigComplete,
12-
validateConfig,
1312
NextConfig,
1413
TurboLoaderItem,
1514
} from './config-shared'
@@ -955,31 +954,36 @@ export default async function loadConfig(
955954
userConfigModule.default || userConfigModule
956955
)
957956

958-
const validateError = validateConfig(userConfig)
957+
if (!process.env.NEXT_MINIMAL) {
958+
// We only validate the config against schema in non minimal mode
959+
const { configSchema } =
960+
require('./config-schema') as typeof import('./config-schema')
961+
const state = configSchema.safeParse(userConfig)
959962

960-
if (validateError) {
961-
// error message header
962-
const messages = [`Invalid ${configFileName} options detected: `]
963+
if (!state.success) {
964+
// error message header
965+
const messages = [`Invalid ${configFileName} options detected: `]
963966

964-
const [errorMessages, shouldExit] = normalizeZodErrors(validateError)
965-
// ident list item
966-
for (const error of errorMessages) {
967-
messages.push(` ${error}`)
968-
}
967+
const [errorMessages, shouldExit] = normalizeZodErrors(state.error)
968+
// ident list item
969+
for (const error of errorMessages) {
970+
messages.push(` ${error}`)
971+
}
969972

970-
// error message footer
971-
messages.push(
972-
'See more info here: https://nextjs.org/docs/messages/invalid-next-config'
973-
)
973+
// error message footer
974+
messages.push(
975+
'See more info here: https://nextjs.org/docs/messages/invalid-next-config'
976+
)
974977

975-
if (shouldExit) {
976-
for (const message of messages) {
977-
console.error(message)
978-
}
979-
await flushAndExit(1)
980-
} else {
981-
for (const message of messages) {
982-
curLog.warn(message)
978+
if (shouldExit) {
979+
for (const message of messages) {
980+
console.error(message)
981+
}
982+
await flushAndExit(1)
983+
} else {
984+
for (const message of messages) {
985+
curLog.warn(message)
986+
}
983987
}
984988
}
985989
}

0 commit comments

Comments
 (0)