解决yarn install 报错 error \node_modules\electron: Command failed.

在电脑重装系统后,重新安装项目依赖,遇到这一报错

完整报错信息如下:

javascript 复制代码
error D:\xxxxx\xxxxxx\node_modules\electron: Command failed.
Exit code: 1
Command: node install.js
Arguments:
Directory: D:\xxxxx\xxxxx\node_modules\electron
Output:
HTTPError: Response code 404 (Not Found) for https://registry.npmmirror.com/electron/v12.2.3/electron-v12.2.3-win32-x64.zip
    at EventEmitter.<anonymous> (D:\xxxxxx\xxxxxx\node_modules\got\source\as-stream.js:35:24)
    at EventEmitter.emit (node:events:514:28)
    at module.exports (D:\xxxxxxx\xxxxxx\node_modules\got\source\get-response.js:22:10)
    at ClientRequest.handleResponse (D:\xxxxxx\xxxxxx\node_modules\got\source\request-as-event-emitter.js:155:5)
    at Object.onceWrapper (node:events:629:26)
    at ClientRequest.emit (node:events:526:35)
    at origin.emit (D:\xxxxxx\xxxxxx\node_modules\@szmarczak\http-timer\source\index.js:37:11) 

错误是因为 Electron 安装时无法从镜像源下载指定版本(electron-v12.2.3-win32-x64.zip),返回了 404。

如何解决:

通过 yarn 的 .yarnrc 文件

在 .yarnrc 中添加:

javascript 复制代码
electron_mirror "https://npmmirror.com/mirrors/electron/"
electron_custom_dir "{{ version }}"

3. 验证配置

运行安装命令时,Electron 会从你配置的镜像地址下载:

补充说明

  • {``{ version }} 是模板变量,实际下载时会替换为 Electron 的具体版本(如 v11.0.0)。

  • 淘宝镜像(npmmirror.com)是 Electron 的国内缓存源,适合解决下载慢或超时问题。

相关推荐
kyriewen28 分钟前
Skills 榜前 10 我全装了:只有 3 个能直接用
前端·javascript·程序员
IT_陈寒1 小时前
当Java的hashCode遇上Lombok,我的缓存被全清了
前端·人工智能·后端
工控丫丫1 小时前
帆软看板中经常使用的公式函数及经常搭的组合
前端·javascript·数据库
jerrywus2 小时前
我用 GPT-6.1-sol 做了台会讲解的 3D 售货机:60 罐饮料,一口没喝上
前端·agent·claude
孟陬3 小时前
Foobar 技术周刊#159:当看不懂代码时,如何高效排障调试。脏页陷阱:一条只读查询,写入数 TB 数据。推测解码:大模型加速利器
前端·人工智能·后端
Zhao-Jichao3 小时前
AI Prompting for Everyone 课程笔记 - P17 图像生成 Imaging Generation
前端
Highcharts.js4 小时前
智能数据分析组件Orbit 正式发布与快速上手体验教程
前端·人工智能·信息可视化·数据分析系统·highcharts·orbit·智能可视化
Dream-Y.ocean4 小时前
鸿蒙PC平台星图遥感适配实战:基于 Electron 壳方案的纯 JavaScript 遥感图像处理引擎开发
javascript·electron·harmonyos
螺丝钉tina4 小时前
[Playwright ][16]Playwright + TypeScript API 自动化测试实战:API测试
前端·javascript·typescript
小天源5 小时前
智叟云集系统 · 架构与职责分层
服务器·前端·数据库