Resolving "Failed to minify the bundle" Errors

TerserWebpackPlugin

The following error message is usually related to running out of memory during a job:

Failed to minify the bundle. Error: static/js/12.fb78ba11.chunk.js from Terser
Error: Call retries were exceeded

Webpack4 uses terser-webpack-plugin to minify your JavaScript as default when mode: 'production' is set. The default parallel option in terser-webpack-plugin is set to the number of CPUs available(os.cpus().length - 1). This means the function references the actual VM's CPU count, which is a higher quantity than what is available to the docker executor. Therefore, Webpack will make more workers than the vCPU counts, and it causes this error.

 

Solution

To work around this, you will need to specify the parallel option to set to the same number as the vCPUs. For example:

const TerserPlugin = require('terser-webpack-plugin');

module.exports = {
  optimization: {
    minimizer: [
      new TerserPlugin({
        parallel: 2,
      }),
    ],
  }
};

More information about this can be found at the link below:

https://webpack.js.org/configuration/optimization/#optimizationminimizer

 

Also, if your project created by create-react-app, it needs to use `eject` or `react-app-rewired` to update Webpack configuration.

 

If it doesn't solve the problem, there are a couple of options you can try:

For additional visibility on memory usage issues, consider logging the maximum memory usage for the job.

Was this article helpful?
2 out of 4 found this helpful

Comments

0 comments

Article is closed for comments.