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

Electron-Updater检测到更新却不下载,报autoDownload非函数错误

解决electron-updater无法自动下载更新及autoUpdater.autoDownload is not a function错误

问题背景

  • 需求:期望electron-updater在新版本发布时自动更新Electron软件
  • 问题:能检测到新版本,但无法下载并安装;使用electron-updater@4.3.8 + electron-builder@8.17.0,切换旧版本也无法解决
  • 当前报错:Electron抛出autoUpdater.autoDownload is not a function错误

相关代码片段

Main.js

// autoUpdater.checkForUpdatesAndNotify() is called in "mainWindow.on('ready-to-show', ...)

// ------ AutoUpdater ------ //
autoUpdater.logger = log;
autoUpdater.logger.transports.file.level = 'info';

const sendStatusToWindow = (text) => {
  log.info(text);
  if (mainWindow) {
    mainWindow.webContents.send('update', text)
  }
}

autoUpdater.on('checking-for-update', () => {
  sendStatusToWindow('Checking for update...')
})

autoUpdater.on('update-available', (info) => {
  sendStatusToWindow('Update available.')
  autoUpdater.autoDownload()
})

autoUpdater.on('update-not-available', (info) => {
  sendStatusToWindow('Update not available.')
})

autoUpdater.on('error', (err) => {
  log.error(`Update-Error: ${err.toString()}`)
  mainWindow.webContents.send('message', `Error in auto-updater: ${err.toString()}`)
})

autoUpdater.on('download-progress', progressObj => {
  sendStatusToWindow(
    `Download speed: ${progressObj.bytesPerSecond} - Downloaded ${progressObj.percent}% (${progressObj.transferred} + '/' + ${progressObj.total} + )`
  )
})

autoUpdater.on('update-downloaded', () => {
  sendStatusToWindow('Update downloaded; will install now')
  autoUpdater.quitAndInstall();
})

Package.json

{
  "name": "iac_2",
  "productName": "IAC 2.0",
  "version": "0.8.3-alpha",
  "homepage": "https://github.com/JueK3y/Instagram-automated-commenting",
  "repository": {
    "type": "git",
    "url": "https://github.com/JueK3y/Instagram-automated-commenting"
  },
  "main": "main.js",
  "scripts": {
    "start": "electron .",
    "test": "echo \"Error: no test specified\" && exit 1",
    "pack": "electron-builder --dir",
    "dist": "electron-builder"
  },
  "devDependencies": {
    "electron": "^15.5.7"
  },
  "dependencies": {
    "electron-log": "^4.4.8",
    "electron-updater": "^4.3.8",
    "electron-window-state": "^5.0.3",
    "is-online": "^9.0.1",
    "keytar": "^7.9.0",
    "network-speed": "^2.1.1",
    "node-notifier": "^10.0.1",
    "puppeteer": "^16.0.0",
    "puppeteer-extra": "^3.3.4",
    "puppeteer-extra-plugin-stealth": "^2.11.0"
  },
  "build": {
    "appId": "jue3ky.iac_2.app",
    "productName": "IAC 2.0",
    "copyright": "Copyright © 2022 by JueK3y",
    "win": {
      "target": "nsis",
      "icon": "icon.ico",
      "publish": {
        "provider": "github"
      }
    },
    "asar": true,
    "asarUnpack": "node_modules/puppeteer/.local-chromium/**/*"
  }
}

解决方案

1. 修复核心API错误

electron-updater@4.x版本中不存在autoDownload()方法,这是混淆了Electron内置autoUpdater和第三方electron-updater的API导致的。electron-updater默认会自动下载更新(可通过autoUpdater.autoDownload = true配置,默认值即为true),直接删除update-available事件中的autoUpdater.autoDownload()调用即可。

2. 修复进度日志语法错误

download-progress事件中的字符串拼接存在错误,修正后才能正确显示下载进度:

// 修正后代码
`Download speed: ${progressObj.bytesPerSecond} - Downloaded ${progressObj.percent}% (${progressObj.transferred}/${progressObj.total})`

3. 解决版本兼容性问题

electron-builder@8.17.0是2017年的老旧版本,和electron-updater@4.3.8、Electron@15.x存在严重兼容性问题。建议升级electron-builder到稳定版本(如24.x+),同时确保electron-updater版本与electron-builder版本匹配(两者通常使用同版本号)。

4. 确认发布配置有效性

确保package.json中build.publish配置正确,GitHub发布需满足:

  • 仓库为公开状态
  • 发布的版本tag与package.json中的version一致
  • electron-builder打包生成的latest.yml文件已上传至GitHub Release

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.22 17:39:20