While building the NodeJs or React application on the command prompt showed an error like FATAL ERROR Ineffective mark-compacts near heap limit Allocation failed JavaScript heap out of memory.

The command is,

npm run build -- --release


the output shows below,


[25302:0x48adf20]    91062 ms: Mark-sweep 492.4 (496.9) -> 491.7 (496.6) MB, 422.4 / 0.0 ms  (+ 158.5 ms in 19 steps since start of marking, biggest step 18.8 ms, walltime since start of marking 643 ms) (average mu = 0.122, current mu = 0.097) allocation 
    0: ExitFrame [pc: 0x140de99]
    1: StubFrame [pc: 0x1394c01]
Security context: 0x3825937808d1

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

 1: 0xa1a640 node::Abort() [/usr/bin/node]


So, you need to check the RAM space in your instance/machine and  set max-old-space-size it based on the your application utilization. Here, we configured with 2 GB space.

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


Now, you can execute the command again and the build should be executed successfully.