reactjsnpmamazon-ec2npm-installnode-sass

AWS: EACCES: permission denied, mkdir '/home/react-app/node_modules/node-sass/vendor'


I have a react-app on aws ec2 instance. I am having trouble installing the npm modules.

Getting this error:

EACCES: permission denied, mkdir '/home/react-app/node_modules/node-sass/vendor'

I have tried this solutions but didn't worked for me.

Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/node-sass/build'

EACCES: permission denied, mkdir '/node_modules/node-sass/build' while running npm install on ubuntu

npm install: Error: EACCES: permission denied, mkdir

Update

sudo npm install --allow-root --unsafe-perm

I tried this and it worked but, when I am going to build the app by

sudo npm run build

which will run this command,

node-sass-chokidar --include-path ./src --include-path ./node_modules src/ -o src/ && react-scripts build

It got stuck/hanged on this line

Creating an optimized production build...

What should I do?


Solution

  • This might be the reason, It is reported that npm run build can fail on machines with limited memory and no swap space, which is common in cloud environments. Even with small projects this command can increase RAM usage in your system by hundreds of megabytes, so if you have less than 1 GB of available memory your build is likely to fail with the following message:

    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.

    If you are completely sure that you didn't terminate the process, consider adding some swap space to the machine you’re building on, or build the project locally.

    Adapted from https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-exits-too-early