'Is there any solution of "JavaScript heap out of memory" & "Array buffer failed"?

error image

I'm building a website with react. But suddenly when I entered npm run start after some time it gave me errors

  1. Fatal error: NewSpace:: Rebalance Allocation failed - JavaScript heap out of memory

  2. Array buffer allocation failed



Solution 1:[1]

Change Your Environment Variables. System -> Advanced system settings -> Environment Variables

Variable Name : NODE_OPTIONS

Variable Value : --max-old-space-size=8192

Solution 2:[2]

You can try to create a secure buffer using this

let buff = Buffer.alloc(15);
buff.fill("a");
console.log(buf);

then try to increase it with the values you have, if you see that it fails is that what you are adding is a very high value, you should not increase the size of the heap as it says in the comments. First you have basic tests, see seeing the values you assign and with that you will locate the error.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 David Prabu
Solution 2 Cerbero