You may encounter an error such as the following while running one of the Snyk 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 the Snyk CLI:

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) and increase the Variable value as shown in the following screenshot:

Or do this in powershell with the following:

 $env:NODE_OPTIONS="--max-old-space-size=8192"

You can also increase the number, if necessary. Some users have increased this up to 14gb for some larger projects.

See also: Out of Memory Error when testing Scala (sbt) project

Reference:

https://stackoverflow.com/questions/53230823/fatal-error-ineffective-mark-compacts-near-heap-limit-allocation-failed-javas

 

https://support.snyk.io/hc/en-us/articles/360002046418-JavaScript-heap-out-of-memory

 

https://fluentprogramming.com/fatal-error-ineffective-mark-compacts-near-heap-limit-allocation-failed-javascript-heap-out-of-memory/

 

https://dev.to/paramagicdev/fixing-fatal-error-ineffective-mark-compacts-near-heap-limit-allocation-failed-javascript-heap-out-of-memory-in-webpacker-2ec5

 

https://exerror.com/fatal-error-ineffective-mark-compacts-near-heap-limit-allocation-failed-javascript-heap-out-of-memory-in-ionic-3/