解决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命令。问题1:发现卡在> node install.js不动参考网上的方法,给npm换源。打开~/.npmrc,修改为registry=https://registry.npm......
解决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中寻找解决方法。
开放原子开发者工作坊旨在鼓励更多人参与开源活动,与志同道合的开发者们相互交流开发经验、分享开发心得、获取前沿技术趋势。工作坊有多种形式的开发者活动,如meetup、训练营等,主打技术交流,干货满满,真诚地邀请各位开发者共同参与!
更多推荐
所有评论(0)