我一直在尝试在我的 package.json 文件上运行 npm install,但我遇到了很多麻烦。它一直在说“错误:尝试解锁尚未锁定的 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 工作,所以也许这也与它有关。
有任何想法吗?
根据 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 上(就像我一样),并且在运行这些命令后仍然看到错误,那么运行最后一个,您应该会很好。(建议您在执行此操作之前尝试测试。除非确实有必要,否则我不喜欢更改整个 /usr/local 目录的权限!)
sudo chown -R $USER /usr/local