Skip to content
Advertisement

Npm error “Error: EACCES: permission denied, mkdir ‘../node-sass/build'”

Can’t install the node-sass package via npm sudo npm i, i have been trying to resolve via sudo npm i -g node-sass --unsafe-perm=true --allow-root but it doesn’t effect. Chmod 777 either. I think there are something with npm permissions but i do not know Log:

JavaScript

Advertisement

Answer

As a general recommendation, never run npm install with sudo as it will create local files owned by root instead of your user, i think you shoud try the following :

  • First change the owner of the folder : chown -R yourusername:yourusername /home/michael/Desktop/react/ , or if you don’t want to type your username : chown -R $USER:$USER /home/michael/Desktop/react/
  • then run : npm install node-sass, do not use sudo

NOTE : This is fine when you install local packages, but for global installations, read the update below


UPDATE

Never Run sudo npm install and sudo npm anything read this article to get an idea why

While changing the permissions by using chown or chmod is kinda fine and works, however it isn’t the best approach when installing packages globally, if you are on a Linux or OSX i would suggest you read this article on the npm docs here, and either use nvm, or manually change npm’s default directory.

Changing npm’s default directory

To do so, you need to follow these steps :

  1. On the command line, in your home directory, create a directory for global installations:

    JavaScript
  2. Configure npm to use the new directory path:

    JavaScript
  3. In your preferred text editor, open or create a ~/.profile file [alternatively you can edit either the ~/.bashrc or ~/.zshrc file instead of .profile if you see fit] and add this line :

    JavaScript
  4. On the command line, update your system variables:

    JavaScript
  5. To test your new configuration, install a package globally without using sudo:

    JavaScript

You can install node-sass globally :

JavaScript

Now you shoudn’t get permissions errors as this should resolve the EACCES permissions errors when installing packages globally .


Warning

LibSass and node-sass are deprecated. While they will continue to receive maintenance releases indefinitely, there are no plans to add additional features or compatibility with any new CSS or Sass features, projects that still use it should move onto Dart Sass. You can read more on this topic here

Please use sass instead, migrating to Dart Sass is straightforward And both packages expose the same JavaScript API, to install dart sass :

JavaScript

Or globally :

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement