Bruno Melofiro
Bruno Melofiro

Reputation: 107

cannot install node-sass therefore cannot install gulp-sass

I'm trying to set up an environment in which I could use a sass compiler with gulp, part of my environment is set up by installing gulp-sass, however, I get an error. After some research, it is apparently because I do not have node-sass. When I try installing node-sass using

sudo npm install -g node-sass

I get the following error, please note that the error for gulp sass is pretty much identical.

/usr/bin/node-sass -> /usr/lib/node_modules/node-sass/bin/node-sass

> [email protected] install /usr/lib/node_modules/node-sass
> node scripts/install.js

Unable to save binary /usr/lib/node_modules/node-sass/vendor/linux-x64-57 : { Error: EACCES: permission denied, mkdir '/usr/lib/node_modules/node-sass/vendor'
    at Object.fs.mkdirSync (fs.js:892:18)
    at sync (/usr/lib/node_modules/node-sass/node_modules/mkdirp/index.js:71:13)
    at Function.sync (/usr/lib/node_modules/node-sass/node_modules/mkdirp/index.js:77:24)
    at checkAndDownloadBinary (/usr/lib/node_modules/node-sass/scripts/install.js:111:11)
    at Object.<anonymous> (/usr/lib/node_modules/node-sass/scripts/install.js:154:1)
    at Module._compile (module.js:624:30)
    at Object.Module._extensions..js (module.js:635:10)
    at Module.load (module.js:545:32)
    at tryModuleLoad (module.js:508:12)
    at Function.Module._load (module.js:500:3)
  errno: -13,
  code: 'EACCES',
  syscall: 'mkdir',
  path: '/usr/lib/node_modules/node-sass/vendor' }

> [email protected] postinstall /usr/lib/node_modules/node-sass
> node scripts/build.js

Building: /usr/bin/node /usr/lib/node_modules/node-sass/node_modules/node-gyp/bin/node-gyp.js rebuild --verbose --libsass_ext= --libsass_cflags= --libsass_ldflags= --libsass_library=
gyp info it worked if it ends with ok
gyp verb cli [ '/usr/bin/node',
gyp verb cli   '/usr/lib/node_modules/node-sass/node_modules/node-gyp/bin/node-gyp.js',
gyp verb cli   'rebuild',
gyp verb cli   '--verbose',
gyp verb cli   '--libsass_ext=',
gyp verb cli   '--libsass_cflags=',
gyp verb cli   '--libsass_ldflags=',
gyp verb cli   '--libsass_library=' ]
gyp info using [email protected]
gyp info using [email protected] | linux | x64
gyp verb command rebuild []
gyp verb command clean []
gyp verb clean removing "build" directory
gyp verb command configure []
gyp verb check python checking for Python executable "python2" in the PATH
gyp verb `which` succeeded python2 /usr/bin/python2
gyp verb check python version `/usr/bin/python2 -c "import platform; print(platform.python_version());"` returned: "2.7.12\n"
gyp verb get node dir no --target version specified, falling back to host node version: 8.7.0
gyp verb command install [ '8.7.0' ]
gyp verb install input version string "8.7.0"
gyp verb install installing version: 8.7.0
gyp verb install --ensure was passed, so won't reinstall if already installed
gyp verb install version is already installed, need to check "installVersion"
gyp verb got "installVersion" 9
gyp verb needs "installVersion" 9
gyp verb install version is good
gyp verb get node dir target node version installed: 8.7.0
gyp verb build dir attempting to create "build" dir: /usr/lib/node_modules/node-sass/build
gyp ERR! configure error 
gyp ERR! stack Error: EACCES: permission denied, mkdir '/usr/lib/node_modules/node-sass/build'
gyp ERR! System Linux 4.4.0-97-generic
gyp ERR! command "/usr/bin/node" "/usr/lib/node_modules/node-sass/node_modules/node-gyp/bin/node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
gyp ERR! cwd /usr/lib/node_modules/node-sass
gyp ERR! node -v v8.7.0
gyp ERR! node-gyp -v v3.6.2
gyp ERR! not ok 
Build failed with error code: 1
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] postinstall: `node scripts/build.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/username/.npm/_logs/2017-10-21T00_11_47_487Z-debug.log

From what I can gather, the problem might either have to do with libsass or node itself but I am at a loss for which steps to follow.

If there are any advice or pointers anyone could give me, I would gladly appreciate it.

Thank you very much!

Upvotes: 8

Views: 17571

Answers (9)

Dushan
Dushan

Reputation: 1565

You can try this command

sudo npm install -g --unsafe-perm node-sass

Upvotes: 2

Hadi Mir
Hadi Mir

Reputation: 5133

Try this

sudo rm -rf node_modules/

sudo npm install --unsafe-perm -g node-sass

sudo npm i

unsafe-perm flag is set to true to suppress the UID/GID (User Identifier/ Group Identifier) switching when running package scripts.The flag is explicitly set to false to prevent non-root user from installing packages.By default its value is false if running as root & true otherwise. If EACCESS error occurs while installing node-saas, then running the installation through sudo and the unsafe-perm flag set to true will install the package.

Upvotes: 0

GuoGuang
GuoGuang

Reputation: 41

I encountered the same problem in the macos system. I deleted the node_modules folder and re-used npm install without sudo to successfully solve this problem.

Upvotes: 0

ivan
ivan

Reputation: 51

i solved running the following

     sudo npm cache clean -f
     sudo npm install -g n
     sudo n stable
     npm rebuild node-sass

Upvotes: 5

Nicolas Hersant
Nicolas Hersant

Reputation: 1

I had the same error message. In my case, it was because i used sudo and non-sudo commands to install node modules, and you shouldn't do that. Delete the node-modules folder. run npm install (without sudo) run sudo npm update that's it, you can run npm start. Hope it will help someone.

Upvotes: 0

Tin Lek
Tin Lek

Reputation: 96

try:

sudo rm -rf node_modules && npm rebuild node-sass && npm i

ref: http://froshgeek.com/fix-npm-error-permission-denied-mkdir-related-to-node-sass-macos/

Upvotes: 5

Sachi Cortes
Sachi Cortes

Reputation: 964

Try the following if you are on ubuntu:

sudo chown -R $(whoami) ~/.npm

Don't use sudo afterwards

Upvotes: 8

Amit Gupta
Amit Gupta

Reputation: 161

This problem typically happens if you run npm install with sudo earlier. Remove node_modules folder and run npm install without sudo

Upvotes: 15

Derek Brown
Derek Brown

Reputation: 4419

This is likely because there are permissions problems with your installation of npm:

  • This page discusses general troubleshooting of these problems with npm. Complete these steps first.

  • This GitHub issue describes someone fixing the exact same issue.

Upvotes: 9

Related Questions