Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
417 views
in Technique[技术] by (71.8m points)

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

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 locked" on all my dependences. Here's one of them:

Error: Attempt to unlock tbd@~0.6.4, which hasn't been locked
        at unlock (/usr/local/lib/node_modules/npm/lib/cache.js:1304:11)
        at cb (/usr/local/lib/node_modules/npm/lib/cache.js:646:5)
        at /usr/local/lib/node_modules/npm/lib/cache.js:655:20
        at /usr/local/lib/node_modules/npm/lib/cache.js:1290:7
        at /usr/local/lib/node_modules/npm/node_modules/lockfile/lockfile.js:167:38
        at OpenReq.Req.done (/usr/local/lib/node_modules/npm/node_modules/graceful-fs/graceful-fs.js:144:5)
        at OpenReq.done (/usr/local/lib/node_modules/npm/node_modules/graceful-fs/graceful-fs.js:64:22)
        at Object.oncomplete (fs.js:107:15)

If I try to run it as sudo, it seems to get further and start installing some packages, but some new errors popup instead:

> [email protected] postinstall /Users/tkirchner/Documents/Projects/mm-datatable/node_modules/karma/node_modules/chokidar
> node setup-deps.js

shell-init: error retrieving current directory: getcwd: cannot access parent directories: Permission denied

node.js:811
    var cwd = process.cwd();
                      ^
Error: EACCES, permission denied
    at Function.startup.resolveArgv0 (node.js:811:23)
    at startup (node.js:58:13)
    at node.js:902:3
npm ERR! error rolling back Error: ENOTEMPTY, rmdir '/Users/tkirchner/Documents/Projects/mm-datatable/node_modules/karma/node_modules/q'
npm ERR! error rolling back  [email protected] { [Error: ENOTEMPTY, rmdir '/Users/tkirchner/Documents/Projects/mm-datatable/node_modules/karma/node_modules/q']
npm ERR! error rolling back   errno: 53,
npm ERR! error rolling back   code: 'ENOTEMPTY',
npm ERR! error rolling back   path: '/Users/tkirchner/Documents/Projects/mm-datatable/node_modules/karma/node_modules/q' }
npm ERR! Error: ENOENT, chown '/Users/tkirchner/Documents/Projects/mm-datatable/node_modules/karma/node_modules/socket.io/lib/socket.io.js'

I recently updated my node and npm installations. So maybe that has something to do with it. Also, most of my development has been at the office and today I'm working over VPN, so maybe that has something to do with it too.

Any ideas?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...