I have a relatively simple React 15 website. It only has a few distinct pages, and it's mainly just text and some pictures. However, when I use react-scripts build
to build the project for production deployment, I'm finding that the node process tops out at around 1.25 GB of RAM used. This hasn't been an issue when building on my workstation, but it's a problem on my production server, where I currently only have 1 GB of RAM available. Most of the time, the server kills my build due to running out of memory.
So it seems my options are to spend more money to upgrade to 2GB of RAM on the server, or find some way to reduce the memory usage. I'd like to avoid paying more, because normally I don't use more than 200 MB of RAM to run my application, and it's just building it that uses a lot of RAM.
I've seems some people recommend adding a --max-old-space-size=
flag to the build, but that doesn't seem to do anything. That is, I've tried this in my package.json:
"build": "react-scripts --max-old-space-size=512 build"
But it still uses up 1+ GB of RAM. I kick off the build via npm run build
, and adding the --max-old-space-size
flag to that npm
command doesn't seem to do anything.
Is there anything I can do to prevent the react-scripts
build process from using so much memory?
--max-old-space-size
would fix it but it doesn't. The only option I see is to go the usual CI route and build it on a separate machine and push the built files to the instance