An example of this error can be found when you have too many modules to
npm install from your
The default Node.js memory limit varies from version to version, but the latest Node.js version 15 still has a memory limit below 2GB.
To fix this kind of error, you need to add the
--max-old-space-size option before running your script.
Here’s an example of increasing the memory limit to 4GB:
node --max-old-space-size=4096 index.js
If you want to add the option when running npm install, you can pass the option from Node.js to npm as follows:
node --max-old-space-size=4096 `which npm` install
If you still see the heap out of memory error, then you may need to increase the heap size even more. The memory size starts from
1024 for 1GB:
--max-old-space-size=1024 # increase memory to 1GB --max-old-space-size=2048 # increase memory to 2GB --max-old-space-size=3072 # increase memory to 3GB --max-old-space-size=4096 # increase memory to 4GB
Many modules downloaded from npm have lots of dependencies on other modules, and some may need to be compiled before they can be used.