'CRA TS React 18.0.0 npm run build issue on AWS EC2

npm run build seems to hang for a long time on my AWS EC2 instance, then I can use the terminal again but a while later the EC2 instance crashes (ssh timeout when connecting until I reboot).

I tried again later with sudo npm run build just to see and that's the first time I noticed the below npm WARN (I may have missed it before, see below snippet). It seemed to get stuck again so after 20 min used ctrl+c to then investigate the below warning.

~/discord-bot/client$ sudo npm run build
npm WARN npm npm does not support Node.js v14.12.0
~/discord-bot/client$ node -v
v16.9.1
~/discord-bot/client$ npm -v
8.0.0

It works locally, I use the same node 16.9.1, however one difference is my local npm version is 7.24.2 instead of 8.0.0. I'll try a clean install of node and make npm versions match to see if that helps but wanted to see first if there are any other ideas.

package.json for the CRA ts project

When installing mui, I had to use --legacy-peer-deps because it wouldn't install with this new version of react. Could this be an issue?

"dependencies": {
    "@emotion/react": "^11.8.2",
    "@emotion/styled": "^11.8.1",
    "@mui/icons-material": "^5.5.1",
    "@mui/material": "^5.5.3",
    "@testing-library/jest-dom": "^5.16.3",
    "@testing-library/react": "^12.1.4",
    "@testing-library/user-event": "^13.5.0",
    "@types/jest": "^27.4.1",
    "@types/node": "^16.11.26",
    "@types/react": "^17.0.43",
    "@types/react-dom": "^17.0.14",
    "axios": "^0.26.1",
    "react": "^18.0.0",
    "react-dom": "^18.0.0",
    "react-router-dom": "^6.3.0",
    "react-scripts": "5.0.0",
    "typeface-roboto": "^1.1.13",
    "typescript": "^4.6.3",
    "web-vitals": "^2.1.4"
  },

I've seen some reports of AWS servers needing more memory to npm run build react apps, but it seems I only have 9% used:

~/discord-bot$ df -hT
Filesystem     Type      Size  Used Avail Use% Mounted on
udev           devtmpfs  476M     0  476M   0% /dev
tmpfs          tmpfs      98M  752K   98M   1% /run
/dev/xvda1     ext4       97G  8.3G   89G   9% /
tmpfs          tmpfs     490M     0  490M   0% /dev/shm
tmpfs          tmpfs     5.0M     0  5.0M   0% /run/lock
tmpfs          tmpfs     490M     0  490M   0% /sys/fs/cgroup
/dev/loop0     squashfs   56M   56M     0 100% /snap/core18/2284
/dev/loop1     squashfs  111M  111M     0 100% /snap/core/12834
/dev/loop2     squashfs  112M  112M     0 100% /snap/core/12941
/dev/loop3     squashfs   25M   25M     0 100% /snap/amazon-ssm-agent/4046
/dev/loop4     squashfs   27M   27M     0 100% /snap/amazon-ssm-agent/5163
/dev/loop5     squashfs   56M   56M     0 100% /snap/core18/2344
tmpfs          tmpfs      98M     0   98M   0% /run/user/1000

I checked /etc/apt/sources.list.d/nodesource.list and it showed 14.x, I'm assuming that should say 16.x since node -v gives v16.9.1. So more reason to try a clean node install I think.

deb https://deb.nodesource.com/node_14.x bionic main
deb-src https://deb.nodesource.com/node_14.x bionic main


Sources

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

Source: Stack Overflow

Solution Source