解决electron安装卡在node install.js和Response 404(Not Found)问题

解决electron安装卡在node install.js和Response 404(Not Found)问题

打算安装一下electron 8.0.2,运行了npm i -D electron@latest命令。

更新记录

2022年7月6日,感谢麦洛_提出的问题,当前博客内容仅供参考,请您根据以下两个建议自行修改,博客文章仍然是旧版。

1.淘宝镜像已经升级了,更换了重新域名,以前的可能随时停
npm config set ELECTRON_MIRROR=“https://npmmirror.com/mirrors/electron/”
2.就是ELECTRON_CUSTOM_DIR不要设置为固定版本号,可以用占位符代替
ELECTRON_CUSTOM_DIR=“{{ version }}”
详情大家可以参加官网:https://www.electronjs.org/zh/docs/latest/tutorial/installation

问题1:发现卡在> node install.js不动

参考网上的方法,给npm换源。

打开~/.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/

再次运行npm i -D electron@latest,不再卡顿

问题2:Response 404(Not Found)

解决了上一个问题出现,未能找到资源。

PS C:\Users\11244> npm i -D electron@latest

> electron@8.0.2 postinstall C:\Users\11244\node_modules\electron
> node install.js

(node:22132) UnhandledPromiseRejectionWarning: HTTPError: Response code 404 (Not Found) for http://npm.taobao.org/mirrors/electron/v8.0.2/electron-v8.0.2-win32-x64.zip
    at EventEmitter.<anonymous> (C:\Users\11244\node_modules\got\source\as-stream.js:35:24)
    at EventEmitter.emit (events.js:210:5)
    at module.exports (C:\Users\11244\node_modules\got\source\get-response.js:22:10)
    at ClientRequest.handleResponse (C:\Users\11244\node_modules\got\source\request-as-event-emitter.js:155:5)
    at Object.onceWrapper (events.js:300:26)
    at ClientRequest.emit (events.js:215:7)
    at ClientRequest.origin.emit (C:\Users\11244\node_modules\@szmarczak\http-timer\source\index.js:37:11)
    at HTTPParser.parserOnIncomingClient [as onIncoming] (_http_client.js:583:27)
    at HTTPParser.parserOnHeadersComplete (_http_common.js:115:17)
    at Socket.socketOnData (_http_client.js:456:22)
(node:22132) 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:22132) [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.
npm WARN saveError ENOENT: no such file or directory, open 'C:\Users\11244\package.json'
npm WARN enoent ENOENT: no such file or directory, open 'C:\Users\11244\package.json'
npm WARN 11244 No description
npm WARN 11244 No repository field.
npm WARN 11244 No README data
npm WARN 11244 No license field.

+ electron@8.0.2
updated 1 package in 1.228s

原因:

Response 404的原因是,换源了之后,淘宝镜像的资源路径和官方的资源路径不同。淘宝的镜像路径是http://npm.taobao.org/mirrors/electron/8.0.2/,而electron官方默认的路径是http://npm.taobao.org/mirrors/electron/v8.0.2/,版本前面加了一个v.

解决方法:

可以修改变量值来修改默认路径。看看@electron/get中使用的url变量,由三部分组成:

url = ELECTRON_MIRROR + ELECTRON_CUSTOM_DIR + '/' + ELECTRON_CUSTOM_FILENAME

修改变量值

npm config set electron_mirror http://npm.taobao.org/mirrors/electron/
npm config set electron_custom_dir 8.0.2

完成

参考

https://blog.tri-lib.com/2019/12/fix-npm-hang-when-install-electron/

反思:

以后遇到这种配置相关的问题,可以直接从项目的github issue中寻找解决方法。

  • 5
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 11
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 11
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值