You need to enable JavaScript to run this app. Electron应用配置自动更新时出现Can not find Squirrel错误
优惠活动
大模型
产品
解决方案
定价
更多

Electron应用配置自动更新时出现Can not find Squirrel错误

Electron自动更新报错 Error: Can not find Squirrel 排查

问题描述

配置Electron应用自动更新功能、测试更新流程时,控制台抛出报错Error: Can not find Squirrel,当前主进程实现代码如下:

const server = 'http://10.172.120.67:8081'
// const url = `${server}/update/${process.platform}/${app.getVersion()}`
const url = `${server}/update/`
console.log(url)
autoUpdater.setFeedURL({ url })
autoUpdater.on('update-downloaded', (event, releaseNotes, releaseName) => {
  console.log("getin")
  const dialogOpts = {
    type: 'info',
    buttons: ['Restart', 'Later'],
    title: 'Application Update',
    message: process.platform === 'win32' ? releaseNotes : releaseName,
    detail: 'A new version has been downloaded. Restart the application to apply the updates.'
  }
  dialog.showMessageBox(dialogOpts).then((returnValue) => {
    if (returnValue.response === 0) autoUpdater.quitAndInstall()
  })
})

autoUpdater.on('error', message => {
  console.error('There was a problem updating the application')
  console.error(message)
})

autoUpdater.on('update-avliable', function (info){
  console.log('update-avliable')
})

autoUpdater.on('checking-for-update', function () {
  console.log('checking-for-update')
});

console.log("hello electron")

autoUpdater.checkForUpdates();

报错核心原因

  • 当前运行的是未经过安装包装机的开发态Electron进程,而非通过安装程序部署的正式版本。Squirrel是Electron自动更新依赖的底层执行组件,仅会在应用通过NSIS、dmg、msi等安装包安装后被部署到系统对应目录;直接通过electron命令、npm脚本启动源码调试时,运行环境内不存在Squirrel可执行文件,直接触发“找不到组件”的错误。
  • 即使Squirrel组件正常加载,现有代码还存在多处会阻断更新流程的问题:
    • 直接引用Electron原生内置的autoUpdater模块,未接入通用的electron-updater依赖,两者的底层实现和接口逻辑不匹配
    • 监听的更新事件名存在拼写错误:代码中写的update-avliable对应正确事件应为update-available,拼写错误会导致该事件永远无法被触发
    • 配置的更新feed路径不符合模块接口规则,无法正常拉取版本元数据

修复方案

  • 不要在开发环境直接测试自动更新全流程,先执行打包命令生成正式安装包,安装到本地系统后再启动应用联调更新逻辑
  • 安装配套依赖electron-updater、electron-builder,在主进程代码中将原生autoUpdater的引用替换为electron-updater导出的实例,保证API逻辑对齐
  • 修正代码中的拼写错误,将update-avliable事件名改为update-available
  • 调整更新feed配置,保证服务端接口可正确返回对应平台的最新版本元数据、安装包资源

内容的提问来源于stack exchange,提问作者Yang.Q

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.25 16:45:07