Ubuntu create-react-app fails with permission denied

前端 未结 6 2050
独厮守ぢ
独厮守ぢ 2021-02-08 12:32

I\'m getting a weird error:

Unhandled rejection Error: EACCES: permission denied, mkdir \'/home/ubuntu/.npm/_cacache/index-v5/14/36\'atus

I jus

相关标签:
6条回答
  • 2021-02-08 13:12

    Remove or rename /home/ubuntu/.npm/_cacache/

    0 讨论(0)
  • 2021-02-08 13:13

    New way of installation will resolve the issue.

    According to the latest react documentation follow below steps to create react app

    npx create-react-app my-app
    cd my-app
    npm start
    

    Note(from ReactJS Team): If you've previously installed create-react-app globally via npm install -g create-react-app, we recommend you uninstall the package using npm uninstall -g create-react-app to ensure that npx always uses the latest version.

    Refer official documentation: https://facebook.github.io/create-react-app/docs/getting-started

    0 讨论(0)
  • 2021-02-08 13:13

    I have same error on Mac catalina 10.15

    You must use sudo, because root is the owner of npm folder, user try to modify some file under npm folder, must run as root by sudo.

    The fix is:

                sudo dojo create app --name hello-world
    
    0 讨论(0)
  • 2021-02-08 13:14

    This problem on a Mac

    Working from Reactjs's Getting Started documentation.

    The Environment

    • OSX Mojave 10.14.3
    • NodeJS v10.15.0

    The Error

    • Command
      npx create-react-app my-app
      
    • Output
      Unhandled rejection Error: EACCES: permission denied, mkdir '/Users/caseywise/.npm/_cacache/index-v5/ae/73'instal
      

    The Fix

    recursively change owner:group on caseywise's NPM preferences directory

    sudo chown -R caseywise:staff '/Users/caseywise/.npm/'
    
    0 讨论(0)
  • 2021-02-08 13:23

    TL;TR

    Run:

    sudo chown -R $USER:$USER '/home/REPLACE_WITH_YOUR_USERNAME/.npm/'
    

    On Linux OS NPM and NodeJS are installed globally with sudo and the owner of that files is the root and usually a user can only read/execute that packages. When NPM is stalled a ~/.npm/ folder is created by the root. By running create-react-app you are executing the command as user and create-react-app is trying to modify something in the ~/.npm/ directory which is owned by the root and not to current user. You need to change the owner of that directory to you, so you can modify it without sudo privileges.

    Often similar thing happens when you install NPM package with sudo e.g. sudo npm install <package> --save. Again the newly installed package in owned by the root and for example when you try to update/modufy/delete your project without sudo infrnt of NPM you will have similar permission error. In these cases navigate to your project directory and change its owner by running:

    sudo chown -R $USER:$USER .
    
    0 讨论(0)
  • 2021-02-08 13:29

    Check the owner of the file with ls -l /problem/dir/. The owner is probably set to root, instead of myUserName (i.e. TWoody).

    You will want to change owner of the .npm/ globally first with chown:

    sudo chown -R $USER: ~/.npm/.

    And if this issue has crept into other /build/ directories after running npm run build, you can go to those directories and run the same command:

    sudo chown -R $USER: ./problem/dir/

    Note that the chown command is using the -R flag to change the user ID and/or group ID for the hierarchies rooted in the files instead of just the files themselves. Also note that the argument $USER: is taking your user name (i.e. myUserName, TWoody) and replacing the "group" ID (the second argument of null) of root.

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