解决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 的国内缓存源,适合解决下载慢或超时问题。

相关推荐
爱分享的鱼鱼4 分钟前
对比理解 Vue 响应式 API:data(), ref、reactive、computed 与 watch 详解
前端·vue.js
JS_GGbond5 分钟前
【性能优化】给Vue应用“瘦身”:让你的网页快如闪电的烹饪秘籍
前端·vue.js
T___T7 分钟前
一个定时器,理清 JavaScript 里的 this
前端·javascript·面试
代码小学僧8 分钟前
从 Arco Table 迁移到 VTable:VTable使用经验分享
前端·react.js·开源
微笑的曙光8 分钟前
Vue3 环境搭建 5 步走(零基础友好)
前端
不知名用户来了13 分钟前
基于vue3 封装的antdv/element-Plus 快速生成增删改查页面
前端
明川18 分钟前
Android Gradle - ASM + AsmClassVisitorFactory插桩使用
android·前端·gradle
San3019 分钟前
深度驱动:React Hooks 核心之 `useState` 与 `useEffect` 实战详解
javascript·react.js·响应式编程
布列瑟农的星空20 分钟前
webpack迁移rsbuild——配置深度对比
前端
前端小黑屋21 分钟前
查看项目中无引用到的文件、函数
前端