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

前端 未结 9 1531
独厮守ぢ
独厮守ぢ 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:08

    I had the same problem and tried to fix the permission/ownership of npm related files and directories for hours but had no luck with that.

    Suddenly I found that I had ~/.npmrc file with cache entry pointing to a non-existing directory. Removed that cache property to use the default cache location and now it's solved.

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

    As per photusenigma at: https://github.com/npm/npm/issues/4815

    Run these commands in a terminal window (note - DON'T replace the $USER part...thats a linux command to get your user!):

    sudo chown -R $USER ~/.npm
    sudo chown -R $USER /usr/local/lib/node_modules
    

    ...and...if you're on a mac (like I am), and still see errors after running these commands, then run this last one and you should be good. (Recommend you try testing before you do this one. I don't like changing the permissions on the ENTIRE /usr/local directory unless it really seems necessary!)

    sudo chown -R $USER /usr/local
    
    0 讨论(0)
  • 2020-12-02 04:17

    None of this worked for me. I had to run literally as root by doing the following:

    sudo su -
    sudo npm install forever -g
    

    Then the package installed on Linux Ubuntu 14.04.

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

    Had the same issue and fixed it by changing the persmissions as per the accepted answer:

    sudo chown -R $USER ~/.npm
    

    However, the second command should be avoided as it downgrades the permissions of a system resource (sudo chown -R $USER /usr/local/lib/node_modules). Not a good idea.

    For the record: "usr" in /usr/local stands for Unix System Resources.

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

    Disclaimer

    I am a Windows user. However, my team and I have come across a number of issues regarding npm installaion errors.

    Problems

    The following is a list of lessons learned and a possible radical solution that has always rescued us:

    1. node_modules, the npm local installation directory becomes protected from modification by a shortcoming of the OS such as the inability to process paths longer than 255 characters.
    2. If the folder is erased by means of a command line tool it may still appear as if the folder exists in the explorer that when trying to access it gives a number of permission errors.
    3. Depending on your antivirus and/or local policy manager you may be able to create the node_modules folder and later relegated access or permissions to it resulting in a number of installation errors.
    4. Enable npm logs to gain further insight into possible problems with:

      npm install --loglevel verbose

    Radical

    Install rimraf globally

     npm install rimraf -g
    

    Run rimraf on node_modules:

    rimraf yourDir/node_modules
    

    Then try running:

    npm install
    

    Warning!

    Or lack there of. Be extremely careful about what follows the command rimraf. There are no warnings, no prompts, there is nothing. It simply erases the directory from the phase of the earth clean, as if it was never there. Try it at your own risk.

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

    I worked with a co-worker this afternoon and figured out what the problem was. My ".npm" folder in my home directory was owned by the root user instead of myself. I'm not sure what happened to cause that. Maybe I installed node or npm as the root admin at one point. In any case I just ran sudo chown -R [username] .npm and I was finally able to run npm install commands from my projects again!

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