一尘不染

NPM无法安装依赖项-尝试解锁尚未锁定的内容

node.js

我一直试图在我的package.json文件上运行npm安装,但是遇到了很多麻烦。我一直依赖于它,一直说“错误:尝试解锁XXX,但尚未锁定”。这是其中之一:

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)

如果我尝试将其作为sudo运行,它似乎会更进一步并开始安装一些软件包,但弹出一些新错误:

> chokidar@0.8.1 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  karma@0.10.9 { [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'

我最近更新了我的节点和npm安装。所以也许与它有关。另外,我的大部分开发工作都在办公室里,今天我正在使用VPN,所以也许与此有关。

有任何想法吗?


阅读 272

收藏
2020-07-07

共1个答案

一尘不染

根据photusenigma:https//github.com/npm/npm/issues/4815

在终端窗口中运行以下命令(注意-不要替换$ USER部分…这是一个Linux命令来获取您的用户!):

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

…并且…如果您使用的是Mac(如我),则在运行这些命令后仍然看到错误,请运行最后一个,您应该会很好。(建议您在进行此操作之前先进行测试。除非确实有必要,否则我不喜欢更改ENTIRE
/ usr / local目录的权限!)

sudo chown -R $USER /usr/local
2020-07-07