@@ -12,6 +12,7 @@ import {
1212import { tags } from '@angular-devkit/core' ;
1313import * as CopyWebpackPlugin from 'copy-webpack-plugin' ;
1414import { existsSync } from 'fs' ;
15+ import { cpus } from 'os' ;
1516import * as path from 'path' ;
1617import { RollupOptions } from 'rollup' ;
1718import { ScriptTarget } from 'typescript' ;
@@ -427,10 +428,16 @@ export function getCommonConfig(wco: WebpackConfigOptions): Configuration {
427428 mangle : allowMangle && buildOptions . platform !== 'server' && ! differentialLoadingMode ,
428429 } ;
429430
431+ // Use up to 7 CPUs for Terser workers, but no more.
432+ // Some environments, like CircleCI, report a large number of CPUs but trying to use them
433+ // Will cause `Error: Call retries were exceeded` errors.
434+ // https://github.com/webpack-contrib/terser-webpack-plugin/issues/143
435+ const maxCpus = Math . min ( cpus ( ) . length , 7 ) ;
436+
430437 extraMinimizers . push (
431438 new TerserPlugin ( {
432439 sourceMap : scriptsSourceMap ,
433- parallel : true ,
440+ parallel : maxCpus ,
434441 cache : ! cachingDisabled && findCachePath ( 'terser-webpack' ) ,
435442 extractComments : false ,
436443 chunkFilter : ( chunk : compilation . Chunk ) =>
@@ -441,7 +448,7 @@ export function getCommonConfig(wco: WebpackConfigOptions): Configuration {
441448 // They are shared between ES2015 & ES5 outputs so must support ES5.
442449 new TerserPlugin ( {
443450 sourceMap : scriptsSourceMap ,
444- parallel : true ,
451+ parallel : maxCpus ,
445452 cache : ! cachingDisabled && findCachePath ( 'terser-webpack' ) ,
446453 extractComments : false ,
447454 chunkFilter : ( chunk : compilation . Chunk ) =>
0 commit comments