Electron 安装错误

MX Lv3

错误描述

昨天安装 electron 时,出现了以下错误:

1
2
3
4
5
~/Desktop/wskt_code/node_modules/.pnpm/electron@35.1.4/node_modules/electron/index.js:17
throw new Error('Electron failed to install correctly, please delete node_modules/electron and try installing again');
^

Error: Electron failed to install correctly, please delete node_modules/electron and try installing again

排查

问了ChatGPT:

  1. pnpm 阻止 Electron 执行安装脚本

    pnpm 在默认情况下为了安全性,可能会阻止某些依赖在 postinstall 阶段执行脚本。而 Electron 需要在安装阶段下载预编译的二进制文件。

    解决方法:

    使用 pnpm approve-builds 命令批准安装 Electron

  2. 切换用 npm 构建

解决

换了npm构建,顺利成功安装。

  • 标题: Electron 安装错误
  • 作者: MX
  • 创建于 : 2025-04-10 13:12:55
  • 更新于 : 2025-04-10 13:19:25
  • 链接: https://www.convolution.fun/2025/04/10/202504101312/
  • 版权声明: 本文章采用 CC BY-NC-SA 4.0 进行许可。
评论
目录
Electron 安装错误