Reputation: 4793
I am currently in a directory containing a node_modules
directory
ls
> coverage etc Gruntfile.js lib node_modules npm-debug.log package.json
From this directory, npm install
spits out the following:
npm ERR! Error: Attempt to unlock [email protected], which hasn't been locked
npm ERR! at unlock (/usr/local/lib/node_modules/npm/lib/cache.js:1434:11)
npm ERR! at cb (/usr/local/lib/node_modules/npm/lib/cache.js:675:5)
npm ERR! at /usr/local/lib/node_modules/npm/lib/cache.js:684:20
npm ERR! at /usr/local/lib/node_modules/npm/lib/cache.js:1420:7
npm ERR! at /usr/local/lib/node_modules/npm/node_modules/lockfile/lockfile.js:167:38
npm ERR! at OpenReq.Req.done (/usr/local/lib/node_modules/npm/node_modules/graceful-fs/graceful-fs.js:144:5)
npm ERR! at OpenReq.done (/usr/local/lib/node_modules/npm/node_modules/graceful-fs/graceful-fs.js:64:22)
npm ERR! at Object.oncomplete (fs.js:107:15)
npm ERR! If you need help, you may report this *entire* log,
npm ERR! including the npm and node versions, at:
npm ERR! <http://github.com/npm/npm/issues>
I tried npm config set prefix /my/path/ --global
, where /my/path/ contains the node_modules directory. I tried using -g --prefix=/my/path. There's no way to change my install directory, apparently by design. Apparently the one and only way to get npm install working, by design, does not work.
Edit: Here's a hacky workaround I had to use in the meantime. This is obviously not ideal but if your system only has one project, it's fine.
sudo npm install
sudo cp /usr/local/lib/node_modules /my/path/ -R
Upvotes: 1
Views: 943
Reputation: 11970
Unless there is more to this that you aren't including, the symptoms here don't have anything to do with the global install location.
The error in the first line of output from npm install
indicates the problem you are trying to solve:
npm ERR! Error: Attempt to unlock [email protected], which hasn't been locked
This suggests your solution is the same as in this other StackOverflow question and is permissions based. A quick search for this error text also results in many similar solutions related to permissions.
Check your directory permissions to be sure ownership is appropriate. If it is, you could also try sudo npm install
but the best answer is to resolve the directory permissions rather than rely upon sudo
.
Upvotes: 3