我正在尝试使用以下命令在MacOS上安装节点:
sudo npm install -g node
这将产生以下输出:
> node@12.6.0 preinstall /usr/local/lib/node_modules/node-darwin-x64/lib/node_modules/node-darwin-x64/lib/node_modules/node
> node installArchSpecificPackage
npm WARN registry Unexpected warning for https://registry.npmjs.org/: Miscellaneous Warning EACCES: EACCES: permission denied, open '/Users/bernhard/.npm/_cacache/tmp/5e859640'
npm WARN registry Using stale data from https://registry.npmjs.org/ due to a request error during revalidation.
npm ERR! path /Users/bernhard/.npm/_cacache/tmp/ef2c2113
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall open
npm ERR! Error: EACCES: permission denied, open '/Users/bernhard/.npm/_cacache/tmp/ef2c2113'
npm ERR! [OperationalError: EACCES: permission denied, open '/Users/bernhard/.npm/_cacache/tmp/ef2c2113'] {
npm ERR! cause: [Error: EACCES: permission denied, open '/Users/bernhard/.npm/_cacache/tmp/ef2c2113'] {
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'open',
npm ERR! path: '/Users/bernhard/.npm/_cacache/tmp/ef2c2113'
npm ERR! },
npm ERR! isOperational: true,
npm ERR! stack: "Error: EACCES: permission denied, open '/Users/bernhard/.npm/_cacache/tmp/ef2c2113'",
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'open',
npm ERR! path: '/Users/bernhard/.npm/_cacache/tmp/ef2c2113'
npm ERR! }
npm ERR!
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR!
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator (though this is not recommended).
/usr/local/lib/node_modules/node-darwin-x64/lib/node_modules/node-darwin-x64/lib/node_modules/node/node_modules/node-bin-setup/index.js:27
throw e;
^
Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/node-darwin-x64/lib/node_modules/node-darwin-x64/lib/node_modules/node/bin'
at Object.mkdirSync (fs.js:764:3)
at ChildProcess.<anonymous> (/usr/local/lib/node_modules/node-darwin-x64/lib/node_modules/node-darwin-x64/lib/node_modules/node/node_modules/node-bin-setup/index.js:24:10)
at ChildProcess.emit (events.js:203:13)
at maybeClose (internal/child_process.js:1021:16)
at Process.ChildProcess._handle.onexit (internal/child_process.js:283:5) {
errno: -13,
syscall: 'mkdir',
code: 'EACCES',
path: '/usr/local/lib/node_modules/node-darwin-x64/lib/node_modules/node-darwin-x64/lib/node_modules/node/bin'
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! node@12.6.0 preinstall: `node installArchSpecificPackage`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the node@12.6.0 preinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/bernhard/.npm/_logs/2019-07-21T16_20_19_759Z-debug.log
预先运行sudo npm cache clean
并没有什么不同。我检查了_cacache
文件夹的权限,并且我的用户对该文件夹拥有完全权限。
关于什么可能导致此问题的任何想法?
答案 0 :(得分:0)
正如其他用户提到的那样,npm本质上是Node.js的一部分(npm install -g node
将安装a global module called "node",与Node.js node
可执行文件不同)。
我的麻烦开始于必须更新节点之后,当执行该操作的(错误)npm命令失败时,我将npm卸载了,以便可以重新安装它。实际上,此时Node.js已被卸载(至少是部分卸载-要么已损坏,要么已损坏)。
通过运行从Node.js网站下载的安装程序重新安装Node.js,可以解决此问题。将来,我将使用推荐的方法之一来更新Node.js,例如this post中描述的方法。