Unverified Commit f2efb502 authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Revert "perf: enable webpack build worker (#57346)" (#57854)

This reverts commit 907f3797.

x-ref: https://github.com/vercel/next.js/pull/57346
parent c0baa0ac
---
title: Webpack Build Worker automatic opt-out
---
## Webpack Build Worker Opt-out
#### Why This Error Occurred
The Next.js config contains custom webpack configuration, as a result, the webpack build worker optimization was disabled.
The webpack build worker optimization helps alleviate memory stress during builds and reduce out-of-memory errors although some custom configurations may not be compatible.
#### Possible Ways to Fix It
You can force enable the option by setting `config.experimental.webpackBuildWorker: true` in the config.
...@@ -1061,35 +1061,16 @@ export default async function build( ...@@ -1061,35 +1061,16 @@ export default async function build(
}) })
const [duration] = process.hrtime(turboNextBuildStart) const [duration] = process.hrtime(turboNextBuildStart)
return { duration, buildTraceContext: undefined } return { duration, buildTraceContext: null }
} }
let buildTraceContext: undefined | BuildTraceContext let buildTraceContext: undefined | BuildTraceContext
let buildTracesPromise: Promise<any> | undefined = undefined let buildTracesPromise: Promise<any> | undefined = undefined
// if the option is set, we respect it, otherwise we check if the user
// has a custom webpack config and disable the build worker by default.
const useBuildWorker =
config.experimental.webpackBuildWorker || !config.webpack
nextBuildSpan.setAttribute(
'has-custom-webpack-config',
String(!!config.webpack)
)
nextBuildSpan.setAttribute('use-build-worker', String(useBuildWorker))
if (
config.webpack &&
config.experimental.webpackBuildWorker === undefined
) {
Log.warn(
'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'
)
}
if (!isGenerate) { if (!isGenerate) {
if (isCompile && useBuildWorker) { if (isCompile && config.experimental.webpackBuildWorker) {
let durationInSeconds = 0 let durationInSeconds = 0
await webpackBuild(true, ['server']).then((res) => { await webpackBuild(['server']).then((res) => {
buildTraceContext = res.buildTraceContext buildTraceContext = res.buildTraceContext
durationInSeconds += res.duration durationInSeconds += res.duration
const buildTraceWorker = new Worker( const buildTraceWorker = new Worker(
...@@ -1118,11 +1099,11 @@ export default async function build( ...@@ -1118,11 +1099,11 @@ export default async function build(
}) })
}) })
await webpackBuild(true, ['edge-server']).then((res) => { await webpackBuild(['edge-server']).then((res) => {
durationInSeconds += res.duration durationInSeconds += res.duration
}) })
await webpackBuild(true, ['client']).then((res) => { await webpackBuild(['client']).then((res) => {
durationInSeconds += res.duration durationInSeconds += res.duration
}) })
...@@ -1138,7 +1119,7 @@ export default async function build( ...@@ -1138,7 +1119,7 @@ export default async function build(
} else { } else {
const { duration: webpackBuildDuration, ...rest } = turboNextBuild const { duration: webpackBuildDuration, ...rest } = turboNextBuild
? await turbopackBuild() ? await turbopackBuild()
: await webpackBuild(false) : await webpackBuild()
buildTraceContext = rest.buildTraceContext buildTraceContext = rest.buildTraceContext
......
...@@ -134,16 +134,17 @@ async function webpackBuildWithWorker( ...@@ -134,16 +134,17 @@ async function webpackBuildWithWorker(
return combinedResult return combinedResult
} }
export function webpackBuild( export async function webpackBuild(
withWorker: boolean,
compilerNames?: typeof ORDERED_COMPILER_NAMES compilerNames?: typeof ORDERED_COMPILER_NAMES
): ReturnType<typeof webpackBuildWithWorker> { ) {
if (withWorker) { const config = NextBuildContext.config!
if (config.experimental.webpackBuildWorker) {
debug('using separate compiler workers') debug('using separate compiler workers')
return webpackBuildWithWorker(compilerNames) return await webpackBuildWithWorker(compilerNames)
} else { } else {
debug('building all compilers in same process') debug('building all compilers in same process')
const webpackBuildImpl = require('./impl').webpackBuildImpl const webpackBuildImpl = require('./impl').webpackBuildImpl
return webpackBuildImpl() return await webpackBuildImpl()
} }
} }
...@@ -282,11 +282,7 @@ export interface ExperimentalConfig { ...@@ -282,11 +282,7 @@ export interface ExperimentalConfig {
typedRoutes?: boolean typedRoutes?: boolean
/** /**
* Run the Webpack build in a separate process to optimize memory usage during build. * This option is to enable running the Webpack build in a worker thread.
* Valid values are:
* - `false`: Disable the Webpack build worker
* - `true`: Enable the Webpack build worker
* - `undefined`: Enable the Webpack build worker only if the webpack config is not customized
*/ */
webpackBuildWorker?: boolean webpackBuildWorker?: boolean
...@@ -780,7 +776,6 @@ export const defaultConfig: NextConfig = { ...@@ -780,7 +776,6 @@ export const defaultConfig: NextConfig = {
typedRoutes: false, typedRoutes: false,
instrumentationHook: false, instrumentationHook: false,
bundlePagesExternals: false, bundlePagesExternals: false,
webpackBuildWorker: undefined,
}, },
} }
......
...@@ -23,10 +23,7 @@ let devOutput ...@@ -23,10 +23,7 @@ let devOutput
() => { () => {
it('should not fail to build invalid usage of the Image component', async () => { it('should not fail to build invalid usage of the Image component', async () => {
const { stderr, code } = await nextBuild(appDir, [], { stderr: true }) const { stderr, code } = await nextBuild(appDir, [], { stderr: true })
const errors = stderr expect(stderr).toBeFalsy()
.split('\n')
.filter((line: string) => line && !line.trim().startsWith('⚠'))
expect(errors).toEqual([])
expect(code).toBe(0) expect(code).toBe(0)
}) })
} }
......
...@@ -25,7 +25,7 @@ let devOutput ...@@ -25,7 +25,7 @@ let devOutput
const { stderr, code } = await nextBuild(appDir, [], { stderr: true }) const { stderr, code } = await nextBuild(appDir, [], { stderr: true })
const errors = stderr const errors = stderr
.split('\n') .split('\n')
.filter((line: string) => line && !line.trim().startsWith('⚠')) .filter((line) => line && !line.trim().startsWith('⚠️'))
expect(errors).toEqual([]) expect(errors).toEqual([])
expect(code).toBe(0) expect(code).toBe(0)
}) })
......
...@@ -22,10 +22,8 @@ const appDir = path.join(__dirname, '..') ...@@ -22,10 +22,8 @@ const appDir = path.join(__dirname, '..')
stdout: true, stdout: true,
stderr: true, stderr: true,
}) })
const errors = stderr console.log(stderr)
.split('\n') expect(stderr.length).toStrictEqual(0)
.filter((line) => line && !line.trim().startsWith('⚠'))
expect(errors).toEqual([])
expect(stdout).toMatch(/Initialized config/) expect(stdout).toMatch(/Initialized config/)
}) })
}) })
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment