From 9a24f621e54c20ea4302a06f02031099508ee683 Mon Sep 17 00:00:00 2001 From: evilebottnawi Date: Tue, 14 Aug 2018 13:22:34 +0300 Subject: [PATCH] fix: `cpus` length in a chroot environment --- src/uglify/Runner.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/uglify/Runner.js b/src/uglify/Runner.js index 69ee09e9..6026e8d7 100644 --- a/src/uglify/Runner.js +++ b/src/uglify/Runner.js @@ -16,7 +16,10 @@ export default class Runner { constructor(options = {}) { const { cache, parallel } = options; this.cacheDir = cache === true ? findCacheDir({ name: 'uglifyjs-webpack-plugin' }) : cache; - this.maxConcurrentWorkers = parallel === true ? os.cpus().length - 1 : Math.min(Number(parallel) || 0, os.cpus().length - 1); + // In some cases cpus() returns undefined + // https://github.com/nodejs/node/issues/19022 + const cpus = (os.cpus() || { length: 1 }); + this.maxConcurrentWorkers = parallel === true ? cpus.length - 1 : Math.min(Number(parallel) || 0, cpus.length - 1); } runTasks(tasks, callback) {