Skip to content

Commit cef8917

Browse files
authored
simplify the way we check for turbopack config to ensure we support an empty turbopack object (#84494)
Previously we 'flattened' all the keys in the config to find unsupported leaf properties, but this meant that an empty object woudln't produce any keys. instead just directly check for the `webpack` and `turbopack` properties and only use the scanning to look for experimental turbopack options and unsupported experimental configuration. Fixes an issue where you cannot bypass the warning simply by adding `turbopack: {}`
1 parent 7f25da7 commit cef8917

File tree

2 files changed

+11
-25
lines changed

2 files changed

+11
-25
lines changed

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

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,6 @@ const unsupportedTurbopackNextConfigOptions = [
4242
'experimental.slowModuleDetection',
4343
]
4444

45-
// The following will need to be supported by `next build --turbopack`
46-
const unsupportedProductionSpecificTurbopackNextConfigOptions: string[] = []
47-
4845
/** */
4946
export async function validateTurboNextConfig({
5047
dir,
@@ -81,23 +78,26 @@ export async function validateTurboNextConfig({
8178
defaultConfig,
8279
})
8380
}
81+
hasWebpackConfig = Boolean(rawNextConfig.webpack)
82+
hasTurboConfig = Boolean(rawNextConfig.turbopack)
8483

8584
const flattenKeys = (obj: any, prefix: string = ''): string[] => {
8685
let keys: string[] = []
8786

8887
for (const key in obj) {
89-
if (typeof obj?.[key] === 'undefined') {
88+
const value = obj?.[key]
89+
if (typeof value === 'undefined') {
9090
continue
9191
}
9292

9393
const pre = prefix.length ? `${prefix}.` : ''
9494

9595
if (
96-
typeof obj[key] === 'object' &&
97-
!Array.isArray(obj[key]) &&
98-
obj[key] !== null
96+
typeof value === 'object' &&
97+
!Array.isArray(value) &&
98+
value !== null
9999
) {
100-
keys = keys.concat(flattenKeys(obj[key], pre + key))
100+
keys = keys.concat(flattenKeys(value, pre + key))
101101
} else {
102102
keys.push(pre + key)
103103
}
@@ -118,23 +118,13 @@ export async function validateTurboNextConfig({
118118

119119
const customKeys = flattenKeys(rawNextConfig)
120120

121-
const unsupportedKeys = isDev
122-
? unsupportedTurbopackNextConfigOptions
123-
: [
124-
...unsupportedTurbopackNextConfigOptions,
125-
...unsupportedProductionSpecificTurbopackNextConfigOptions,
126-
]
127-
128121
for (const key of customKeys) {
129-
if (key.startsWith('webpack') && rawNextConfig.webpack) {
130-
hasWebpackConfig = true
131-
}
132-
if (key.startsWith('turbopack') || key.startsWith('experimental.turbo')) {
122+
if (key.startsWith('experimental.turbo')) {
133123
hasTurboConfig = true
134124
}
135125

136126
const isUnsupported =
137-
unsupportedKeys.some(
127+
unsupportedTurbopackNextConfigOptions.some(
138128
(unsupportedKey) =>
139129
// Either the key matches (or is a more specific subkey) of
140130
// unsupportedKey, or the key is the path to a specific subkey.

test/e2e/config-turbopack/index.test.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,7 @@ export default function Page() {
8989
'next.config.js': `
9090
module.exports = {
9191
turbopack: {
92-
rules: {
93-
'*.foo': {
94-
loaders: ['foo-loader']
95-
}
96-
}
92+
9793
},
9894
webpack: (config) => {
9995
return config

0 commit comments

Comments
 (0)