2

We have an angular 5 project which has a problem with size. On load of the app, when there isn't much of anything, we have 95MB in memory. I'm trying to analyze it and use webpack-bundle-analyzer.

I've read that adding new webpack.optimize.ModuleConcatenationPlugin() into webpack.config should help, so I did and it helped (from 95 to 76MB).

But when I run build with stats after that npm run build:stats > stats.json ("build:stats": "webpack --profile --json --config webpack.config.buildserver.js") I get this message FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory

Before adding the plugin, the stats.json file had around 390 000 lines of json object.

I found that there is a memory flag for node scripts --max_new_space_size but I can't find anything similar for webpack script.

I'm not sure what to look for, could anyone help please?

Laker
  • 1,622
  • 4
  • 20
  • 32

2 Answers2

2

It's a known bug, you can check this issue for more details and also try to install this npm package and run before you build and after npm install.

cassmtnr
  • 927
  • 13
  • 26
1

To set Node.js flags one can use NODE_OPTIONS env variable.

For example, building stats in webpack version 4:

NODE_OPTIONS="--max-old-space-size=4096" webpack --json > stats.json