NPM cannot install dependencies - Attempt to unlock something which hasn't been locked

前端 未结 9 1532
独厮守ぢ
独厮守ぢ 2020-12-02 03:59

I\'ve been trying to run an npm install on my package.json file, but I\'m having a lot of trouble. It keeps saying \"Error: Attempt to unlock XXX, which hasn\'t been locke

相关标签:
9条回答
  • 2020-12-02 04:30

    The following command should fix permission issues:

    sudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules,bin,share}
    

    You can read about another officially recommended solutions here:

    https://docs.npmjs.com/getting-started/fixing-npm-permissions

    0 讨论(0)
  • 2020-12-02 04:31

    In my case the issue was invoking npm with a user that does not have a HOME directory, so for example the following command would fail:

    sudo -u someUser npm install
    

    The solution is to provide a HOME directory, where someUser has write access:

    sudo -u someUser HOME=/some/directory npm install
    
    0 讨论(0)
  • 2020-12-02 04:34

    My solution:

    sudo chown -R $USER /usr/local/lib/node_modules/NAMEOFMODULE
    

    in my case was :

    sudo chown -R $USER /usr/local/lib/node_modules/appium/
    

    But I was getting the same problem, finally after

    npm cache clean
    

    it worked !

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