The Issue:

This “Reached heap limit Allocation” issue mainly occurs due to memory leaks or insufficient default memory for running large projects.

Also, if you use Node.js and update to a different version.

How to determine the current heap limit Allocation:

node -e 'console.log(v8.getHeapStatistics().heap_size_limit/(1024*1024))'


 

Solution:

Execute this command in the terminal where you run the Node.js process:

export NODE_OPTIONS="--max-old-space-size=8192"


 

Note:

The max-old-space-size value can be any number based on your project’s requirements. It is not required to specify the value in gigabytes (GB); it can be any number of memory megabytes (MB).

#increase to 1gb
export NODE_OPTIONS="--max-old-space-size=1024"

#increase to 2gb
export NODE_OPTIONS="--max-old-space-size=2048" 

#increase to 3gb
export NODE_OPTIONS="--max-old-space-size=3072"

#increase to 4gb
export NODE_OPTIONS="--max-old-space-size=4096"

#increase to 5gb
export NODE_OPTIONS="--max-old-space-size=5120"

#increase to 6gb
export NODE_OPTIONS="--max-old-space-size=6144"

#increase to 7gb
export NODE_OPTIONS="--max-old-space-size=7168"

#increase to 8gb 
export NODE_OPTIONS="--max-old-space-size=8192" 


Always input memory size in MB to avoid program errors. Avoid allocating all available memory to prevent system crashes.

Happy learning/coding 😎