Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow max heap size to be configured globally #18889

Closed
mischkl opened this issue Feb 20, 2018 · 8 comments
Closed

Allow max heap size to be configured globally #18889

mischkl opened this issue Feb 20, 2018 · 8 comments
Labels
cli Issues and PRs related to the Node.js command line interface. feature request Issues that request new features to be added to Node.js. v8 engine Issues and PRs related to the V8 dependency.

Comments

@mischkl
Copy link

mischkl commented Feb 20, 2018

  • 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.

npm/npm#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.

@addaleax
Copy link
Member

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

@addaleax addaleax added v8 engine Issues and PRs related to the V8 dependency. feature request Issues that request new features to be added to Node.js. cli Issues and PRs related to the Node.js command line interface. labels Feb 20, 2018
@mischkl
Copy link
Author

mischkl commented Feb 20, 2018

Yes, I suppose that is exactly what I meant. 😃

@mischkl mischkl closed this as completed Feb 20, 2018
@petesouthwell
Copy link

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.

@rodneymullen2
Copy link

still no solution for this? I have the same issue

@Therealskythe
Copy link

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.

@valex91
Copy link

valex91 commented Nov 8, 2019

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.

@douglasg14b
Copy link

douglasg14b commented Jan 10, 2022

@valex91 That does not seem to work.

After setting the environmental variable, opening a new terminal, and running v8.getHeapStatistics() It still shows ~1GB as the heap_size_limit

image

@sharmaAshish-dev
Copy link

@valex91 That does not seem to work.

After setting the environmental variable, opening a new terminal, and running v8.getHeapStatistics() It still shows ~1GB as the heap_size_limit

image

did you find any solution yet?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cli Issues and PRs related to the Node.js command line interface. feature request Issues that request new features to be added to Node.js. v8 engine Issues and PRs related to the V8 dependency.
Projects
None yet
Development

No branches or pull requests

8 participants