You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Windows Terminal管理员身份安装Electron报错,请求问题排查

Electron安装失败的问题分析与解决步骤

你这是碰到了两个关联问题:权限不足导致的文件清理失败,以及Electron安装包损坏导致的校验和不匹配。具体错误日志如下:

PS C:\xampp\htdocs\name> npm install electron

npm warn deprecated boolean@3.2.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

npm warn cleanup Failed to remove some directories [

npm warn cleanup   [

npm warn cleanup     'C:\\xampp\\htdocs\\name\\node_modules\\@szmarczak',

npm warn cleanup     [Error: EPERM: operation not permitted, rmdir 'C:\xampp\htdocs\name\node_modules\@szmarczak\http-timer\dist'] {

npm warn cleanup       errno: -4048,

npm warn cleanup       code: 'EPERM',

npm warn cleanup       syscall: 'rmdir',

npm warn cleanup       path: 'C:\\xampp\\htdocs\\name\\node_modules\\@szmarczak\\http-timer\\dist'

npm warn cleanup     }

npm warn cleanup   ],

npm warn cleanup   [

npm warn cleanup     'C:\\xampp\\htdocs\\name\\node_modules',

npm warn cleanup     [Error: EPERM: operation not permitted, rmdir 'C:\xampp\htdocs\name\node_modules\got\dist\source'] {

npm warn cleanup       errno: -4048,

npm warn cleanup       code: 'EPERM',

npm warn cleanup       syscall: 'rmdir',

npm warn cleanup       path: 'C:\\xampp\\htdocs\\name\\node_modules\\got\\dist\\source'

npm warn cleanup     }

npm warn cleanup   ]

npm warn cleanup ]

npm error code 1

npm error path C:\xampp\htdocs\name\node_modules\electron

npm error command failed

npm error command C:\\WINDOWS\\system32\\cmd.exe /d /s /c node install.js

npm error Error: Generated checksum for "electron-v33.2.0-win32-x64.zip" did not match expected checksum.

npm error     at Hash.<anonymous> (C:\xampp\htdocs\name\node_modules\sumchecker\index.js:133:20)

npm error     at Hash.emit (node:events:519:28)

npm error     at emitReadable_ (node:internal/streams/readable:832:12)

npm error     at onEofChunk (node:internal/streams/readable:810:5)

npm error     at readableAddChunkPushByteMode (node:internal/streams/readable:464:5)

npm error     at Readable.push (node:internal/streams/readable:390:5)

npm error     at node:internal/streams/transform:141:12

npm error     at Hash._flush (node:internal/crypto/hash:104:3)

npm error     at Hash.final [as _final] (node:internal/streams/transform:128:10)

npm error     at prefinish (node:internal/streams/writable:914:14)

npm error A complete log of this run can be found in: C:\Users\sum1\AppData\Local\npm-cache\_logs\2024-11-14T01_52_50_541Z-debug-0.log

问题原因

  1. EPERM权限错误:哪怕是以管理员身份运行终端,也可能因为文件被其他进程(比如Node.js后台进程、杀毒软件实时扫描)占用,导致npm没法删除旧的node_modules目录。
  2. 校验和不匹配:下载的Electron安装包在传输过程中损坏了,本地计算的校验和和官方预期对不上,所以安装直接终止。

解决步骤

  • 第一步:关掉占用文件的进程
    打开任务管理器,结束所有Node.js、npm相关的进程;暂时关闭杀毒软件的实时保护,避免它拦着文件操作。

  • 第二步:清理残留文件和缓存

    1. 删掉项目目录下的node_modules文件夹和package-lock.json文件;
    2. 执行命令清空npm缓存:
      npm cache clean --force
      
  • 第三步:重新安装Electron
    直接跑安装命令就行,如果还是失败,可以指定国内npm镜像源来提升下载稳定性:

    npm install electron --registry=国内npm镜像源地址
    

    常用的国内镜像源比如npmmirror,你可以自行找官方地址替换。

  • 备选方案:手动换安装包
    如果下载一直失败,你可以手动从Electron官方渠道下载对应版本的electron-v33.2.0-win32-x64.zip,放到npm缓存目录(路径可以看日志里的C:\Users\sum1\AppData\Local\npm-cache,找到对应子文件夹),然后再重新执行安装命令。

内容的提问来源于stack exchange,提问作者Eiom

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.16 05:59:50