electron安装失败

安装electron

bash 复制代码
//指定版本可以改为 npm install --save-dev electron@22.3.0
npm install --save-dev electron

安装失败 RequestError: connect ETIMEDOUT 20.205.243.166:443

less 复制代码
npm error code 1
npm error path E:\project\work\xxx\xxx\node_modules\electron
npm error command failed
npm error command C:\WINDOWS\system32\cmd.exe /d /s /c node install.js
npm error RequestError: connect ETIMEDOUT 20.205.243.166:443
npm error     at ClientRequest.<anonymous> (E:\project\work\xxx\xxx\node_modules\got\dist\source\core\index.js:970:111)
npm error     at Object.onceWrapper (node:events:623:26)
npm error     at ClientRequest.emit (node:events:520:35)
npm error     at origin.emit (E:\project\work\xxx\xxx\node_modules\@szmarczak\http-timer\dist\source\index.js:43:20)
npm error     at emitErrorEvent (node:_http_client:107:11)
npm error     at TLSSocket.socketErrorListener (node:_http_client:574:5)
npm error     at TLSSocket.emit (node:events:508:28)
npm error     at emitErrorNT (node:internal/streams/destroy:170:8)
npm error     at emitErrorCloseNT (node:internal/streams/destroy:129:3)
npm error     at process.processTicksAndRejections (node:internal/process/task_queues:90:21)
npm error     at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1637:16)
npm error A complete log of this run can be found in: C:\Users\xxx\AppData\Local\npm-cache\_logs\2025-09-08T10_00_30_300Z-debug-0.log

解决:

  • 安装 pnpm
bash 复制代码
npm install -g pnpm
  • 安装 pnpm 失败,执行如下命令
bash 复制代码
npm install -g pnpm --registry=https://registry.npmmirror.com
  • 或者设置pnpm使用国内镜像源(配置后建议关闭终端后再重新打开新的终端)
bash 复制代码
pnpm config set registry https://registry.npmmirror.com
  • 查看当前的 registry 镜像
bash 复制代码
npm config get registry
  • 或者在根目录配置 .npmrc 文件,可以确保大部分走国内镜像
  • 内容如下
ini 复制代码
registry=https://registry.npmmirror.com
ELECTRON_MIRROR=https://npmmirror.com/mirrors/electron/
PUPPETEER_DOWNLOAD_HOST=https://npmmirror.com/mirrors
  • 如果无法安装pnpm,考虑下载最新版 Node.js
  • pnpm 来安装 electron
bash 复制代码
pnpm install electron --save-dev
  • 安装继续失败报错:ssh: connect to host github.com port 22: Connection timed out

  • 配置Git对GitHub使用HTTPS协议

  • 一定要加 --add 不然会被覆盖

bash 复制代码
# 配置Git对GitHub使用HTTPS协议
# 这将使Git在获取GitHub仓库时使用HTTPS而不是SSH
git config --global --add url."https://github.com/".insteadOf git@github.com:

# 或者专门针对GitHub配置
git config --global --add url."https://github.com/".insteadOf ssh://git@github.com/
  • 配置后用如下命令检查是否设置成功
bash 复制代码
git config --global --list
  • 你应该看到 两条规则:
ini 复制代码
url.https://github.com/.insteadof=ssh://git@github.com/
url.https://github.com/.insteadOf=git@github.com:
  • git配置成功后一定要关闭当前的终端,重新开一个终端,再去安装 electron
bash 复制代码
npm install

#或者
pnpm install

#等等命令
...
相关推荐
H_老邪1 天前
Vue + Electron 项目快速上手指南
前端·vue.js·electron
floret. 小花1 天前
Vue3 + Electron 知识点总结 · 2026-03-21
前端·面试·electron·学习笔记·vue3
码路飞2 天前
Electron 太胖了?试试 Electrobun,12MB 打包一个 AI 桌面助手
typescript·electron
floret. 小花2 天前
Vue3 知识点总结 · 2026-03-20
前端·面试·electron·学习笔记·vue3
梦鱼3 天前
🖥️ 告别 Electron 托盘图标模糊:一套精准的 PNG 生成方案
前端·electron
家里有蜘蛛4 天前
Electron 桌面应用多实例实践:数据隔离与跨进程互斥
electron
前端Hardy5 天前
Electrobun 正式登场:仅 12MB,JS 桌面开发迎来轻量化新方案!
前端·javascript·electron
羊吖6 天前
Vue3 + Electron 实现纯本地人脸识别登录一体机(离线可用、无云端、带页面跳转)
前端·javascript·electron
卸载引擎6 天前
NTP 授时(Network Time Protocol)核心解读,工控机electron程序自动联网授时案例
前端·javascript·electron