How to fix EACCES issues with npm install

前端 未结 3 1947
心在旅途
心在旅途 2020-12-03 06:13

Some of my node modules get installed but there are always these sort of issues on this particular linux mint machine

npm install 

npm ERR! Error: EACCES,         


        
相关标签:
3条回答
  • 2020-12-03 06:30

    UPDATE. See this answer for a better way.


    You have to set correct permissions (ownership) so npm can access your (sub)directories with your normal user permissions:

    sudo chown -R $USER <directory>
    

    where in your case <directory> is /home/me and -R is for recursive to also change ownership of all your subdirectories, which is exactly what you want. That should fix the EACCESS issue.

    Sadly the advise to run the command as root/Administrator is wrong here.

    You want to avoid running npm with sudo ever, as recommended by the npm creator Isaac Schlueter:

    I strongly encourage you not to do package management with sudo! Packages can run arbitrary scripts, which makes sudoing a package manager command as safe as a chainsaw haircut. Sure, it’s fast and definitely going to cut through any obstacles, but you might actually want that obstacle to stay there.

    See here for more details.

    0 讨论(0)
  • 2020-12-03 06:41

    Try to use "sudo npx create-react-app app-name" it may still show error because some dependencies may be mising but a directory and the necessary files maybe created.

    0 讨论(0)
  • 2020-12-03 06:52

    This code fix it for me.

    sudo chown -R `whoami` ~/.npm
    sudo chown -R `whoami` /usr/local/lib/node_modules
    
    0 讨论(0)
提交回复
热议问题