I'm currently running a react front end with yarn as my package manager. Any time I attempt to run yarn build, the build fails with the following error:
The build failed because the process exited too early. This probably means the system ran out of memory or someone called kill -9 on the process.
This error only occurs when I try to run on my linode cloud server which has 2GB RAM and 50Gb storage, the server is dedicated to running this one app and the app size itself is very small. The build also runs on my local host which I run on my macbook - also using the yarn package manager and the same node version.
I ensure I run yarn cache clean as well as the same command with the all flag set at times as well and delete the yarn.lock file as well as my node_modules to attempt to have a clean attempt when trying a new solution.
The tricky part is that the build error message gives very little details:
yarn run v1.22.19
$ react-scripts --max_old_space_size=4096 build
Creating an optimized production build...
The build failed because the process exited too early. This probably means the system ran out of memory or someone called `kill -9` on the process.
error Command failed with exit code 1.
My package.json is as follows:
{
"name": "notus-react",
"version": "1.1.0",
"proxy": "https://whizzdom.co.uk",
"license": "MIT",
"dependencies": {
"@emotion/react": "^11.10.5",
"@emotion/styled": "^11.10.5",
"@fortawesome/fontawesome-free": "5.15.3",
"@material-ui/core": "^4.12.3",
"@material-ui/lab": "^4.0.0-alpha.60",
"@mui/icons-material": "^5.8.4",
"@mui/material": "^5.11.6",
"@mui/styles": "^5.8.6",
"@mui/x-data-grid": "^5.12.3",
"@mui/x-date-pickers": "^5.0.0-beta.3",
"@popperjs/core": "2.9.1",
"@tailwindcss/forms": "0.2.1",
"autoprefixer": "10.2.5",
"axios": "^0.21.4",
"chart.js": "2.9.4",
"formik": "^2.2.9",
"formik-material-ui": "^3.0.1",
"formik-material-ui-lab": "^0.0.8",
"gulp": "^4.0.2",
"gulp-append-prepend": "1.0.8",
"node": "^18.4.0",
"postcss": "8.2.8",
"react": "17.0.1",
"react-datepicker": "^4.8.0",
"react-dom": "17.0.1",
"react-helmet": "^6.1.0",
"react-router": "5.2.0",
"react-router-dom": "5.2.0",
"react-scripts": "4.0.3",
"recharts": "^2.1.9",
"sass": "^1.54.3",
"scrollreveal": "^4.0.9",
"tailwindcss": "2.0.4",
"universal-cookie": "^4.0.4",
"yup": "^0.32.11"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts --max_old_space_size=4096 build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"install:clean": "rm -rf node_modules/ && rm -rf package-lock.json && npm install && npm run build:tailwind && npm start",
"build:tailwind": "tailwind build src/assets/styles/index.css -o src/assets/styles/tailwind.css"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"optionalDependencies": {
"typescript": "4.2.3"
}
}
Please let me know if there's any other information needed to help diagnose the problem - going a bit crazy here so any help would be deeply appreciated.
I've tried:
uninstalling my version of node (v16.13) and reinstalling it again
using a different node version
uninstalling and reinstalling yarn (v1.22.19)
manually allocating more data from the build via ENV NODE_OPTIONS=--max_old_space_size=4096
I also tried with different values ie 4096, 8192 and all the other multiples plus non multiples.
Trying to roll back and use my last package.json file and the dependencies listed there.
Running the yarn commands with sudo in front of it in case there was a permissions error
Running top to monitor the yarn build - this just shows me the memory increasing up until the limit I allocate and then the build fails. The name it comes under is node.
Your VPS' 2GB of RAM doesn't appear to be enough to build your app. I'd recommend either: Setting up a swap partition on your server (if using Linux), or build locally and rsync it to the server (the build OS and server OS must match) or up the RAM via selecting a different linode server.