gyp ERR! stack Error: EACCES: permission denied, mkdir '/var/www/project_name/node_modules/node-sass/build'

Viewed 28398

I'm deploying an Angular project on Ububtu 16.04 and get these errors when I run sudo npm install. (won't work without sudo). It seems that npm doesn't have permission to install. I recently updated to nodejs to 8.11.4 and still have the same error so it wasn't a version problem apparently. How can I give it the correct permissions?

gyp ERR! configure error 
gyp ERR! stack Error: EACCES: permission denied, mkdir '/var/www/project_name/node_modules/node-sass/build'
gyp ERR! System Linux 4.4.0-1065-aws
gyp ERR! command "/usr/local/bin/node" "/var/www/project_name/node_modules/node-gyp/bin/node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "-libsass_library="
gyp ERR! cwd /var/www/front-stormsensor/node_modules/node-sass
gyp ERR! node -v v8.11.4
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok 
Build failed with error code: 1

Is there something off within my project? Or an incorrect installation? Not sure where to go from here, thank you

9 Answers

try the following command

sudo npm i --unsafe-perm

if it doesn't work try the following

sudo rm -rf ~/.node-gyp
sudo npm cache clean -f
sudo npm install -g n
sudo n stable
sudo npm i --unsafe-perm

I fixed it by run this command.

sudo npm i --unsafe-perm

In case you're installing something globally, you can use:

$ sudo npm install -g <package> --unsafe-perm

use following command to install

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

This solution from jnambiar worked for me. My OS is OSX 10.11.6. It's basically permissions issue.

sudo rm -rf ~/.node-gyp
sudo npm cache clean -f
sudo npm install -g n
sudo n stable
sudo npm i --unsafe-perm

Above set of commands helped me resolve the issue. I am posting this to approve the set of commands which worked for me while I struggled to install the node-sass package for 2 days.

For anyone that might still have this problem, I solved it by following the suggestion of the second comment above and logging in as the root user on my ubuntu instance, as described in the second answer on this question here.. That allowed me to npm install without errors.

I used yarn instead of npm and it worked

npm permissions are quite a headache. The above solutions didn't work on my machine. Yarn did the trick. sudo npm i yarn -g yarn add

This command worked for me on windows.. sudo npm install --unsafe-perm

Related