Skip to content

Commit e240292

Browse files
committed
Implement the warning/error
1 parent 969d06a commit e240292

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

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

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,7 @@ const unsupportedTurbopackNextConfigOptions = [
4747
]
4848

4949
// The following will need to be supported by `next build --turbopack`
50-
const unsupportedProductionSpecificTurbopackNextConfigOptions: string[] = [
51-
// TODO: Support disabling sourcemaps, currently they're always enabled.
52-
// 'productionBrowserSourceMaps',
53-
]
50+
const unsupportedProductionSpecificTurbopackNextConfigOptions: string[] = []
5451

5552
/** */
5653
export async function validateTurboNextConfig({
@@ -125,7 +122,7 @@ export async function validateTurboNextConfig({
125122

126123
const customKeys = flattenKeys(rawNextConfig)
127124

128-
let unsupportedKeys = isDev
125+
const unsupportedKeys = isDev
129126
? unsupportedTurbopackNextConfigOptions
130127
: [
131128
...unsupportedTurbopackNextConfigOptions,
@@ -140,7 +137,7 @@ export async function validateTurboNextConfig({
140137
hasTurboConfig = true
141138
}
142139

143-
let isUnsupported =
140+
const isUnsupported =
144141
unsupportedKeys.some(
145142
(unsupportedKey) =>
146143
// Either the key matches (or is a more specific subkey) of
@@ -163,13 +160,23 @@ export async function validateTurboNextConfig({
163160
Log.error('Unexpected error occurred while checking config', e)
164161
}
165162

166-
if (hasWebpackConfig && !hasTurboConfig) {
167-
Log.warn(
168-
`Webpack is configured while Turbopack is not, which may cause problems.`
163+
// If the build was defaulted to Turbopack, we want to warn about possibly ignored webpack configuration.
164+
// Othwerwise the user explicitly picked turbopack and thus we expect that they have configured it correctly.
165+
if (process.env.TURBOPACK === 'auto' && hasWebpackConfig && !hasTurboConfig) {
166+
const logMethod = isDev ? Log.warn : Log.error
167+
// In a production build with auto-detected Turbopack, we want to fail the build.
168+
logMethod(`Webpack is configured while Turbopack is not.`)
169+
logMethod(
170+
`See instructions if you need to configure Turbopack:\n https://nextjs.org/docs/app/api-reference/next-config-js/turbopack`
169171
)
170-
Log.warn(
171-
`See instructions if you need to configure Turbopack:\n https://nextjs.org/docs/app/api-reference/next-config-js/turbopack\n`
172+
logMethod(
173+
`TIP: Silence this ${isDev ? 'warning' : 'error'} by passing the --turbopack or --webpack flag explicitly.`
172174
)
175+
176+
// For production builds we want to simply fail to prevent accidental misconfiguration.
177+
if (!isDev) {
178+
process.exit(1)
179+
}
173180
}
174181

175182
if (unsupportedConfig.length) {

0 commit comments

Comments
 (0)