Node.js heap out of memory
Solution 1:
If I remember correctly, there is a strict standard limit for the memory usage in V8 of around 1.7 GB, if you do not increase it manually.
In one of our products we followed this solution in our deploy script:
node --max-old-space-size=4096 yourFile.js
There would also be a new space command but as I read here: a-tour-of-v8-garbage-collection the new space only collects the newly created short-term data and the old space contains all referenced data structures which should be in your case the best option.
Solution 2:
If you want to increase the memory usage of the node globally - not only single script, you can export environment variable, like this:export NODE_OPTIONS=--max_old_space_size=4096
Then you do not need to play with files when running builds like
npm run build
.
Solution 3:
Just in case anyone runs into this in an environment where they cannot set node properties directly (in my case a build tool):
NODE_OPTIONS="--max-old-space-size=4096" node ...
You can set the node options using an environment variable if you cannot pass them on the command line.