From 1516361e1f021a8bfcfbf2a3fa158b9d0038b682 Mon Sep 17 00:00:00 2001 From: Christoph Tavan Date: Fri, 25 Oct 2019 15:06:41 +0200 Subject: [PATCH] Only enable worker threads if there is more than 1 worker Multiple worker threads can cause problems when certain dependencies are being used, see e.g. https://github.com/zeit/next.js/issues/7894 This patch allows disabling of worker threads by setting `config.experimental.cpus = 1`. The benefit of spawning 1 worker thread, if there is any at all, should very limited anyways, so the workload can just as well be processed in the main thread. --- packages/next/build/index.ts | 2 +- .../webpack/plugins/terser-webpack-plugin/src/TaskRunner.js | 2 +- packages/next/export/index.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/next/build/index.ts b/packages/next/build/index.ts index 3feb83a48b348..2a2cd8d1b0845 100644 --- a/packages/next/build/index.ts +++ b/packages/next/build/index.ts @@ -337,7 +337,7 @@ export default async function build(dir: string, conf = null): Promise { const staticCheckWorkers = new Worker(staticCheckWorker, { numWorkers: config.experimental.cpus, - enableWorkerThreads: true, + enableWorkerThreads: config.experimental.cpus > 1, }) const analysisBegin = process.hrtime() diff --git a/packages/next/build/webpack/plugins/terser-webpack-plugin/src/TaskRunner.js b/packages/next/build/webpack/plugins/terser-webpack-plugin/src/TaskRunner.js index b306966292ede..cb905786e3ea2 100644 --- a/packages/next/build/webpack/plugins/terser-webpack-plugin/src/TaskRunner.js +++ b/packages/next/build/webpack/plugins/terser-webpack-plugin/src/TaskRunner.js @@ -28,8 +28,8 @@ export default class TaskRunner { if (this.maxConcurrentWorkers > 1) { this.workers = new Worker(worker, { - enableWorkerThreads: true, numWorkers: this.maxConcurrentWorkers, + enableWorkerThreads: this.maxConcurrentWorkers > 1, }) this.boundWorkers = options => this.workers.default(options) } else { diff --git a/packages/next/export/index.ts b/packages/next/export/index.ts index dba1116a3f3d1..0792904475bf4 100644 --- a/packages/next/export/index.ts +++ b/packages/next/export/index.ts @@ -267,7 +267,7 @@ export default async function( { maxRetries: 0, numWorkers: threads, - enableWorkerThreads: true, + enableWorkerThreads: threads > 1, exposedMethods: ['default'], } ) as any