FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory

When having node applications in production you may have come to encounter this issue and it's basically an error that occurs when the memory consumption comes close to the default of 512MB, which is pretty low for most hardware.

What you do to battle this error is quite simple. Just add the following as an argument to your production process:

--max-old-space-size <megabytes>

So if you're running node with systemd and have 2gb of memory available on the machine, this is a good config:

/home/username/.nvm/versions/node/version/bin/node --max-old-space-size=1536 /home/username/app/app.js

Why to use


Instead of 2GB is simply because it's good to leave some memory for other stuff like the database, web server or similar. Otherwise, node will probably eat that memory too and the system will start writing to the swap file and slow things down.

Command line options | Node.js v14.8.0 Documentation
Show Comments