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

前端 未结 4 715
栀梦
栀梦 2021-02-14 14:45

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

相关标签:
4条回答
  • 2021-02-14 14:58

    Do nothing .. simply add --unsafe-perm to it

    Give it unsafe permission access.

    So, let's say.. if you were previously installing bcrypt library

    sudo npm install --save bcrypt
    

    then now write

    sudo npm install --unsafe-perm --save bcrypt
    

    And you are done.

    0 讨论(0)
  • 2021-02-14 15:01

    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
    0 讨论(0)
  • 2021-02-14 15:06

    I solved this issue by running

    sudo npm install -g --unsafe-perm node-sass
    
    0 讨论(0)
  • 2021-02-14 15:07

    I followed the instructions as per @WaLid LamRaoui's answer as I also use to run npm install with sudo. It seemed to have done the trick in terms of changing the owner of the folder, but I still got an error when trying to run npm install. I then realized another problem which has to do with my cache folder which contains root-owned files, so for those whose also have this problem after following the approved answer, I simply did this:

    sudo chown -R 1003:1003 "/home/<username>/.npm"
    

    After this I ran npm install and it worked fine.

    0 讨论(0)
提交回复
热议问题