Increase JavaScript Heap size in create-react-app project
"build": "react-scripts --max_old_space_size=4096 build"
This should work
Thanks a lot to @dan-abramov as his comment is the answer! (Give him the vote up in case you come across this).
You can just put e.g. node --max_old_space_size=4096 node_modules/.bin/react-scripts start
in there instead of react-scripts start