terser-webpack-plugin: Webpack build hangs with parallel: true

  • Operating System: Windows 10 1810, WSL, Ubuntu 18.04
  • Node Version: 8.12.0
  • NPM Version: 6.4.1
  • webpack Version: 4.19.1
  • terser-webpack-plugin Version: 1.1.0

Expected Behavior

That the webpack build completes

Actual Behavior

The webpack build hangs forever (or at least 30 minutes which is the longest I have lasted) after outputting

Compilation  starting…

However changing parallel: true to parallel: false in terser options will cause the build to complete in normal time (around 40s)

Code

new TerserPlugin({
        terserOptions: {
          parse: {
            // we want terser to parse ecma 8 code. However, we don't want it
            // to apply any minfication steps that turns valid ecma 5 code
            // into invalid ecma 5 code. This is why the 'compress' and 'output'
            // sections only apply transformations that are ecma 5 safe
            // https://github.com/facebook/create-react-app/pull/4234
            ecma: 8
          },
          compress: {
            ecma: 5,
            warnings: false,
            // Disabled because of an issue with Uglify breaking seemingly valid code:
            // https://github.com/facebook/create-react-app/issues/2376
            // Pending further investigation:
            // https://github.com/mishoo/UglifyJS2/issues/2011
            comparisons: false,
            // Disabled because of an issue with Terser breaking valid code:
            // https://github.com/facebook/create-react-app/issues/5250
            // Pending futher investigation:
            // https://github.com/terser-js/terser/issues/120
            inline: 2
          },
          mangle: {
            safari10: true
          },
          output: {
            ecma: 5,
            comments: false,
            // Turned on because emoji and regex is not minified properly using default
            // https://github.com/facebook/create-react-app/issues/2488
            ascii_only: true
          }
        },
        // Use multi-process parallel running to improve the build speed
        // Default number of concurrent runs: os.cpus().length - 1
        parallel: true,
        // Enable file caching
        cache: true,
        sourceMap: shouldUseSourceMap
      })

Full webpack config: https://github.com/Pajn/tscomp/blob/cra2/config/webpack.config.prod.js

How Do We Reproduce?

I suspect this can be related to WSL. If you have some debugging tips I can probably run them.

For the exact same state as I have:

  1. Clone https://github.com/Pajn/tscomp
  2. git checkout terser-bug
  3. Clone https://github.com/Pajn/RAXA
  4. cd RAXA/packages/web
  5. yarn
  6. yarn add --dev path/to/cloned/tscomp/repo
  7. yarn build, or for more information NODE_ENV=production webpack --config node_modules/tscomp/config/webpack.config.prod.js --verbose --info-verbosity verbose --display verbose --profile

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 12
  • Comments: 71 (39 by maintainers)

Most upvoted comments

Okey, we disable parallels on WSL and for 2.0 we migrate on jest-worker (they work with WSL) https://github.com/webpack-contrib/terser-webpack-plugin/issues/89

I’ve just tried to reproduce https://github.com/vuejs/vue-cli/issues/3327 with parallel: true on WSL (1803) again and couldn’t get into the lock situation anymore. Looks like the issue was fixed in WSL.

I’m sorry. I gave up on trying to use Windows for development because problems like this was the norm and not an exception so now I only have Linux to test on.

I am on 1803. Surprisingly it worked now for my repo now on WSL😃.Previously it wasn’t working, had to manually disable parallel

Edit: let me try the repro test Edit 2: Doesn’t work on the https://github.com/webpack-contrib/terser-webpack-plugin/issues/21#issuecomment-456324702

image

Very interesting because it is working on my local repo that once had this problem, but still not working on the reproducible repo. Could it be a dependency problem ?

This thread caught my eye as I was searching for possible reasons we are seeing CI builds occasionally time out (webpack hanging for 45+ minutes). We are not running WSL, but this in particular stood out to me:

if you watch Task Manager you’ll notice that eventually the node processes will just cease utilizing CPU resource with the build reporting 92% chunk asset optimization TerserPlugin (as pictured below)

I’ve seen our build hang for a while running locally on my Mac, and it was always at 92%. I haven’t been able to get any more details out of our CI build hangs yet, but I’m going to test the parallel setting and see if it makes any difference.

I should note that this is an intermittent issue for us; I’m not sure if other people are seeing this consistently or not.