在Mac上使用命令'sudo npm installelectron -g'在Mac上安装Electron后,如何解决此错误?

时间:2020-02-21 14:18:09

标签: javascript node.js macos npm electron

我在命令前加上sudo,因为我第一次尝试时遇到了“权限被拒绝” 错误。建议以管理员身份运行命令,或者最好还是删除/usr/local/lib/node_modules上的整个电子文件夹并重新安装。我这样做了,并第二次安装了它,但是仍然出现以下错误:

(node:85821) UnhandledPromiseRejectionWarning: Error: EACCES: permission denied, mkdtemp '/usr/local/lib/node_modules/electron/electron-download-KXtUtz'
(node:85821) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:85821) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

+ electron@8.0.1

added 85 packages from 93 contributors in 8.968s
➜  / electron -v

/usr/local/lib/node_modules/electron/index.js:14
    throw new Error(**'Electron failed to install correctly, please delete node_modules/electron and try installing again'**)

2 个答案:

答案 0 :(得分:0)

这终于对我有用:

sudo npm install electronic -g --unsafe-perm = true

通过此链接https://www.electronjs.org/docs/tutorial/installation

答案 1 :(得分:0)

这是我安装带有全局标志的Electron版本8.2.2的方法:

npm install -g --unsafe-perm=true electron