Skip to content

Commit f2efb50

Browse files
authored
Revert "perf: enable webpack build worker (#57346)" (#57854)
This reverts commit 907f379. x-ref: #57346
1 parent c0baa0a commit f2efb50

File tree

7 files changed

+18
-61
lines changed

7 files changed

+18
-61
lines changed

errors/webpack-build-worker-opt-out.mdx

Lines changed: 0 additions & 15 deletions
This file was deleted.

packages/next/src/build/index.ts

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,35 +1061,16 @@ export default async function build(
10611061
})
10621062

10631063
const [duration] = process.hrtime(turboNextBuildStart)
1064-
return { duration, buildTraceContext: undefined }
1064+
return { duration, buildTraceContext: null }
10651065
}
10661066
let buildTraceContext: undefined | BuildTraceContext
10671067
let buildTracesPromise: Promise<any> | undefined = undefined
10681068

1069-
// if the option is set, we respect it, otherwise we check if the user
1070-
// has a custom webpack config and disable the build worker by default.
1071-
const useBuildWorker =
1072-
config.experimental.webpackBuildWorker || !config.webpack
1073-
nextBuildSpan.setAttribute(
1074-
'has-custom-webpack-config',
1075-
String(!!config.webpack)
1076-
)
1077-
nextBuildSpan.setAttribute('use-build-worker', String(useBuildWorker))
1078-
1079-
if (
1080-
config.webpack &&
1081-
config.experimental.webpackBuildWorker === undefined
1082-
) {
1083-
Log.warn(
1084-
'Custom webpack configuration is detected. When using a custom webpack configuration, the Webpack build worker is disabled by default. To force enable it, set the "experimental.webpackBuildWorker" option to "true". Read more: https://nextjs.org/docs/messages/webpack-build-worker-opt-out'
1085-
)
1086-
}
1087-
10881069
if (!isGenerate) {
1089-
if (isCompile && useBuildWorker) {
1070+
if (isCompile && config.experimental.webpackBuildWorker) {
10901071
let durationInSeconds = 0
10911072

1092-
await webpackBuild(true, ['server']).then((res) => {
1073+
await webpackBuild(['server']).then((res) => {
10931074
buildTraceContext = res.buildTraceContext
10941075
durationInSeconds += res.duration
10951076
const buildTraceWorker = new Worker(
@@ -1118,11 +1099,11 @@ export default async function build(
11181099
})
11191100
})
11201101

1121-
await webpackBuild(true, ['edge-server']).then((res) => {
1102+
await webpackBuild(['edge-server']).then((res) => {
11221103
durationInSeconds += res.duration
11231104
})
11241105

1125-
await webpackBuild(true, ['client']).then((res) => {
1106+
await webpackBuild(['client']).then((res) => {
11261107
durationInSeconds += res.duration
11271108
})
11281109

@@ -1138,7 +1119,7 @@ export default async function build(
11381119
} else {
11391120
const { duration: webpackBuildDuration, ...rest } = turboNextBuild
11401121
? await turbopackBuild()
1141-
: await webpackBuild(false)
1122+
: await webpackBuild()
11421123

11431124
buildTraceContext = rest.buildTraceContext
11441125

packages/next/src/build/webpack-build/index.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,16 +134,17 @@ async function webpackBuildWithWorker(
134134
return combinedResult
135135
}
136136

137-
export function webpackBuild(
138-
withWorker: boolean,
137+
export async function webpackBuild(
139138
compilerNames?: typeof ORDERED_COMPILER_NAMES
140-
): ReturnType<typeof webpackBuildWithWorker> {
141-
if (withWorker) {
139+
) {
140+
const config = NextBuildContext.config!
141+
142+
if (config.experimental.webpackBuildWorker) {
142143
debug('using separate compiler workers')
143-
return webpackBuildWithWorker(compilerNames)
144+
return await webpackBuildWithWorker(compilerNames)
144145
} else {
145146
debug('building all compilers in same process')
146147
const webpackBuildImpl = require('./impl').webpackBuildImpl
147-
return webpackBuildImpl()
148+
return await webpackBuildImpl()
148149
}
149150
}

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -282,11 +282,7 @@ export interface ExperimentalConfig {
282282
typedRoutes?: boolean
283283

284284
/**
285-
* Run the Webpack build in a separate process to optimize memory usage during build.
286-
* Valid values are:
287-
* - `false`: Disable the Webpack build worker
288-
* - `true`: Enable the Webpack build worker
289-
* - `undefined`: Enable the Webpack build worker only if the webpack config is not customized
285+
* This option is to enable running the Webpack build in a worker thread.
290286
*/
291287
webpackBuildWorker?: boolean
292288

@@ -780,7 +776,6 @@ export const defaultConfig: NextConfig = {
780776
typedRoutes: false,
781777
instrumentationHook: false,
782778
bundlePagesExternals: false,
783-
webpackBuildWorker: undefined,
784779
},
785780
}
786781

test/integration/next-image-legacy/svgo-webpack/test/index.test.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,7 @@ let devOutput
2323
() => {
2424
it('should not fail to build invalid usage of the Image component', async () => {
2525
const { stderr, code } = await nextBuild(appDir, [], { stderr: true })
26-
const errors = stderr
27-
.split('\n')
28-
.filter((line: string) => line && !line.trim().startsWith('⚠'))
29-
expect(errors).toEqual([])
26+
expect(stderr).toBeFalsy()
3027
expect(code).toBe(0)
3128
})
3229
}

test/integration/next-image-new/svgo-webpack/test/index.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ let devOutput
2525
const { stderr, code } = await nextBuild(appDir, [], { stderr: true })
2626
const errors = stderr
2727
.split('\n')
28-
.filter((line: string) => line && !line.trim().startsWith('⚠'))
28+
.filter((line) => line && !line.trim().startsWith('⚠'))
2929
expect(errors).toEqual([])
3030
expect(code).toBe(0)
3131
})

test/integration/webpack-require-hook/test/index.test.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,8 @@ const appDir = path.join(__dirname, '..')
2222
stdout: true,
2323
stderr: true,
2424
})
25-
const errors = stderr
26-
.split('\n')
27-
.filter((line) => line && !line.trim().startsWith('⚠'))
28-
expect(errors).toEqual([])
25+
console.log(stderr)
26+
expect(stderr.length).toStrictEqual(0)
2927
expect(stdout).toMatch(/Initialized config/)
3028
})
3129
})

0 commit comments

Comments
 (0)