Ubuntu create-react-app fails with permission denied

前端 未结 6 2071
独厮守ぢ
独厮守ぢ 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: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 --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 .
    

提交回复
热议问题