Problem
When I use the ionic serve command to launch an Ionic 3 project, I receive the following error:
Asked by Himanshu Shekhar
Solution #1
For people who come across this topic on Google and want a non-Angular generic answer:
Every time you get this issue, it’s most likely due to a memory leak or a difference in memory management between Node.js = 10 and Node.js > 10.
Increasing the memory allotted to Node is usually all that is required. While it will let your program to execute, it may not actually address the problem, and the node process’ memory usage may still surpass the new memory you allocate. When your Node.js process starts up or you upgrade to Node, I recommend analyzing memory use. > 10 js
I had a problem with my memory. A fantastic post on debugging memory leaks in Node can be found here. js.
To increase RAM, perform the following commands in the terminal where you run your Node.js process:
export NODE_OPTIONS="--max-old-space-size=8192"
where max-old-space-size can be [2048, 4096, 8192, 16384], and so on.
For more clarification, consider the following examples:
export NODE_OPTIONS="--max-old-space-size=5120" # Increase to 5 GB
export NODE_OPTIONS="--max-old-space-size=6144" # Increase to 6 GB
export NODE_OPTIONS="--max-old-space-size=7168" # Increase to 7 GB
export NODE_OPTIONS="--max-old-space-size=8192" # Increase to 8 GB
# and so on...
# formula:
export NODE_OPTIONS="--max-old-space-size=(X * 1024)" # Increase to X GB
# Note: it doesn't have to be multiples of 1024.
# max-old-space-size can be any number of memory megabytes (MB) you have available.
Run this command in your terminal to see the current (not precise but very close) value of max-old-space-size (in MB).
node -e 'console.log(v8.getHeapStatistics().heap_size_limit/(1024*1024))'
Answered by Emmanuel N K
Solution #2
In my instance, I was able to resolve the issue by installing Node.js version 12.10.0.
Answered by Germán Ayala
Solution #3
I had the same problem on CentOS 7, but this fixed it for me:
node --max-old-space-size=X node_modules/@angular/cli/bin/ng build --prod
Where X = (2048, 4096, 8192, etc.) is the memory value.
Answered by Hakim CHRIFI ALAOUI
Solution #4
Just type this in the terminal:
export NODE_OPTIONS="--max-old-space-size=8192"
The issue happens when the default maximum memory limit for Node.js is exceeded. All this does is boost the amount of RAM that can be used.
Answered by Matt
Solution #5
When I used the ng build command in Visual Studio Code, I got the same issue. But if I do the same thing on the Windows command line in the following order, I can build successfully.
Step 1.
set NODE_OPTIONS=--max_old_space_size=4096
Step 2.
ng build
Answered by Sushrut Singh Sisodiya
Post is based on https://stackoverflow.com/questions/53230823/fatal-error-ineffective-mark-compacts-near-heap-limit-allocation-failed-javas