webpack: Compile stuck at optimize chunk assets

I’ve started having problems to compile my build when --optimize-minimize is enabled. I see that I’ve reached +/-205 build modules, and then the compilation gets stuck at 80% optimize chunk assets for a very long time (+40minutes).
If I wait enough, it ends up node failing with “fatal error: js allocation failed - process out of memory”

I guess it has to do with the uglifyjs plugin as I said this only happens when using --optimize-minime flag (When compiling through my grunt task, this also fails).

About this issue

  • Original URL
  • State: closed
  • Created 10 years ago
  • Comments: 88 (21 by maintainers)

Commits related to this issue

Most upvoted comments

@sokra Could you comment on why you closed this? Has a fix from uglify been pulled in to fix the problem with already-compiled files?

@fresheneesz: I added it to the UglifyJS plugin config as suggested a few posts up. I actually found the root cause of my problem, which may be what others were experiencing. It turns out I was using the UglifyJsPlugin in the config file but also running webpack -p, so optimizing twice. When I removed the -p from the CLI command, everything worked. More here: https://github.com/webpack/webpack/issues/1385#issuecomment-160553651

If still getting stuck/crashing due to OOM at 78%, after removing any pre-minified assets, you may want to try running WebPack with more memory than Node’s default and a larger thread pool. You can use the UV_THREADPOOL_SIZE environment variable to set the size of the thread pool, and Node’s –max_old_space_size=SIZE_IN_MB argument to increase the Node’s memory limit.

For example:

UV_THREADPOOL_SIZE=100 node --max_old_space_size=4096 node_modules/webpack/bin/webpack.js --config config/webpack/production.js

Additionally, I use the following configuration for the UglifyJS plugin for production and it works fine when given enough resources as noted above…it just takes a good bit longer than desired:

new webpack.optimize.UglifyJsPlugin({
            sourceMap: false,
            minimize: true,
            compress: {
                drop_debugger: true,
                warnings: false,
                drop_console: true
            }
})

I know much of this has been mentioned in this issue, but wanted to put the core workarounds that I found together in one place for people searching.

Increasing swap worked for me!

Regarding the original issue:

new UglifyJsPlugin({
  sourceMap: false
})

instead of --optimize-minimize or -p should help…

We’re also running into this issue and have worked-around exactly as @dougcalobrisi suggests. It’s slow, but at least it doesn’t die.

Try to remove dev-tool: source-map, then it will be much faster. But I’m still trying to figure out how can keep source-map.

Using

new UglifyJsPlugin({
    sourceMap: false
})

Burns 100% of the cpu for >45minutes before I gave up and killed the process.

Running uglifyjs on webpack’s output completes in a matter of seconds.

Have the same issue here, without UglifyJsPlugin. Do you have any idea when can this be fixed?

anyway. Thanks for the webpack! incredible pice of art.

Had this same issue, building was taking 10mins+ and as a few people have noted, i took out my minified dependencies and it now builds in ~10s 😄.