At times you may find that you encounter an error such as the following while running one of Snyk's CLI commands:
FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
This generally occurs on larger projects where the default amount of memory allocated by node (1.5gb) is insufficient to complete the command successfully.
Resolution
You can increase the amount of memory allocated to the command by running the following command prior to running Snyk:
Linux/macOS
export NODE_OPTIONS=--max-old-space-size=8192
For example:
export NODE_OPTIONS=--max-old-space-size=8192
snyk test
export NODE_OPTIONS=--max-old-space-size=8192
snyk monitor
Windows
From the control panel go to System -> Advanced system settings -> Environment Variables -> New (user or system)
Or this can be done in powershell with:
$env:NODE_OPTIONS="--max-old-space-size=8192"
You can also increase this number, if necessary. We've seen folks need to increase this up to 14gb for some larger projects!
See also: Out of Memory Error when testing Scala (SBT) project