解决electron安装报错

358 阅读1分钟
原文链接: www.ufotool.com

# 解决electron安装报错

# 问题描述

如果出现如下错误关键词:

postinstall: node install.js npm ERR! Exit status 1 npm ERR! npm
ERR! Failed at the electron@6.0.8 postinstall 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!
1
2
3
4

# 解决方案

表示要下载 electron错误,解决方法有两种如下:

  1. 先把node_modules中的electron删掉
  2. 按如下方法执行 方法一: 编辑 ~/.npmrc 加入下面内容
registry=https://registry.npm.taobao.org
sass_binary_site=https://npm.taobao.org/mirrors/node-sass/
phantomjs_cdnurl=http://npm.taobao.org/mirrors/phantomjs
ELECTRON_MIRROR=http://npm.taobao.org/mirrors/electron/
1
2
3
4

然后重新安装即可;

npm install --unsafe-perm=true --allow-root
1

方法二: 设置淘宝镜像源(推荐使用nrm,这一步是为了保证其他依赖不报错)

npm install -g nrm
nrm use taobao
1
2

设置环境变量并安装

# Mac系统
ELECTRON_MIRROR=http://npm.taobao.org/mirrors/electron/ npm install  --unsafe-perm=true --allow-root

# Windows系统
set "ELECTRON_MIRROR=http://npm.taobao.org/mirrors/electron/" && npm install --unsafe-perm=true --allow-root
1
2
3
4
5

执行上面的命令即可。



MIT Licensed | Copyright © 2019 www.ufotool.com @HomeEmail

粤ICP备18032999号-1 @百度统计