Node: Allow max heap size to be configured globally

Created on 20 Feb 2018  路  6Comments  路  Source: nodejs/node

  • Version: 8.9.1
  • Platform: Windows
  • Subsystem:


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.

V8 Engine cli feature request

Most helpful comment

You mean something like env NODE_OPTIONS=--max_old_space_size=4096 node ./node_modules/.bin/webpack? Because that exists :)

All 6 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

filipesilvaa picture filipesilvaa  路  3Comments

fanjunzhi picture fanjunzhi  路  3Comments

stevenvachon picture stevenvachon  路  3Comments

sandeepks1 picture sandeepks1  路  3Comments

Icemic picture Icemic  路  3Comments