When building your React app, you might encounter FATAL ERROR: Reached heap limit. This happens because the VM has limited memory (e.g., 1 GiB). Here’s how to fix it:
Increase Memory for Node.js:
Update the build script in package.json:
json
Copy
"build": "node --max-old-space-size=2048 $(which react-scripts) build"
This allocates 2 GB of memory for the build process.
Add Swap Space:
Create a swap file to provide additional virtual memory:
bash
Copy
sudo fallocate -l 2G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
Rebuild the App:
Run the build again:
bash
Copy
npm run build
This resolves memory issues during the build process.