At the moment certain node processes, e.g. Webpack when building large projects, consistently lead to the out-of-memory error FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
. While it is possible to increase the heap size by calling e.g. node --max-old-space-size=4096 ./node_modules/.bin/webpack
this is not ideal, especially when executing scripts via NPM defined on the package.json
's scripts
field.
https://github.com/npm/npm/issues/12238 gives an idea of how cumbersome it is to have to preface every script name with node --max-old-space-size=4096 ./node_modules/.bin/
. Meanwhile other solutions such as https://github.com/endel/increase-memory-limit are ugly hacks at best.
This all could be avoided if Node offered a way to globally configure the max heap size, for instance via an environmental variable or a config file. When using Node for frontend tooling there isn't the luxury of just one or two scripts needing to be launched once and then let run forever. There are tons of different scripts used for all kinds of purposes that developers execute in the course of their daily work, and it would be great if there was a simple way to set the max heap size to be higher for all of them.
You mean something like env NODE_OPTIONS=--max_old_space_size=4096 node ./node_modules/.bin/webpack
? Because that exists :)
Yes, I suppose that is exactly what I meant. :smiley:
Im glad they had this.. Thanks.
However. Id not mind a simple..... memory=grow_as_you_need
RIGHT!!??!??!!
And while were being this fancy.. How about that's the default.... And the guys that'd like to UBER Tame the memory to be exactly so.. Can customize that. Just a thought!! Still thanks for informing about the flag. Appreciated.
still no solution for this? I have the same issue
Where do you enter that?
Why does half the internet say max_old_space_size
is deprecated?
Why is there no usable documentation for this project? Google and Github and blogs are full with the same old obvious questions and we're all wasting our time here.
Where do you enter that?
Why does half the internet say
max_old_space_size
is deprecated?Why is there no usable documentation for this project? Google and Github and blogs are full with the same old obvious questions and we're all wasting our time here.
I've had to create the same thing for my company, I've tried numerous solution, none of them working. So I create a bash script that work on macOS and windows( if you got any terminal simulator like the git bash )
https://gist.github.com/valex91/8402175bba1c9c43bc666c249ec1fd83
usage ./increaseNodeSize.sh <amount>
remeber to chmod it properly on macOS
if you don't have any bash simulator, on windows you can simply run
setx NODE_OPTIONS "--max-old-space-size=<amount>"
which will setup a persistent env variable that node will pick up every time it run.
Most helpful comment
You mean something like
env NODE_OPTIONS=--max_old_space_size=4096 node ./node_modules/.bin/webpack
? Because that exists :)