electron-userland / electron-builder

A complete solution to package and build a ready for distribution Electron app with “auto update” support out of the box
https://www.electron.build
MIT License
13.71k stars 1.74k forks source link

Install fails after download – Cannot read property 'version' of undefined #3898

Closed JsseL closed 5 years ago

JsseL commented 5 years ago

Other version information:

  http_parser: '2.7.0',
  node: '8.2.1',
  v8: '5.9.211.38',
  uv: '1.13.1',
  zlib: '1.2.11',
  ares: '1.10.1-DEV',
  modules: '57',
  openssl: '1.0.2l',
  electron: '1.8.8',
  chrome: '59.0.3071.115',
  'atom-shell': '1.8.8'

What happens:

See electron-updater debug logs:

Checking for update
Found version 1.1.4-beta (url: My-App-1.1.4-beta.exe)
Downloading update from My-App-1.1.4-beta.exe
Cached update sha512 checksum doesn't match the latest available update. New update must be downloaded. Cached: sfGv+2uclxwOn8fF9oswI8VhBmpav6n02T5t+7zox9F+4I8Loiktnt07x73E1kzIVRiECo+EQ+Gdh+ycHNl3f
w==, expected: yA9anLOgGrs4AeJglJqU7VgybSX2ULROsfX5KDBpjZLMiU/zN12RKSQA9fOEt/3/XfliirJdRFvCEqOPSHHSNQ==. Directory for cached update will be cleaned
Download block maps (old: "https://service.com/myapp/downloads/My-App-1.1.3-beta.exe.blockmap", new: https://service.com/myapp/downloads/My-App-1.1.4-beta.exe.blockmap)
File has 870 changed blocks
Full: 32,435.11 KB, To download: 17,409.49 KB (54%)
close 9 C:\Users\me\AppData\Roaming\My-App\__installer.exe
New version 1.1.4-beta has been downloaded to C:\Users\me\AppData\Roaming\My-App\__update__\My-App-1.1.4-beta.exe
Error: TypeError: Cannot read property 'version' of undefined
    at NsisUpdater.autoUpdater.on (C:\Users\me\Documents\projects\myapp\app\backend\backendUpdater.js:103:106)
    at emitOne (events.js:115:13)
    at NsisUpdater.emit (events.js:210:7)
    at NsisUpdater.dispatchUpdateDownloaded (C:\Users\me\Documents\projects\myapp\app\node_modules\electron-updater\src\AppUpdater.ts:430:10)
    at Object.<anonymous> (C:\Users\me\Documents\projects\myapp\app\node_modules\electron-updater\src\BaseUpdater.ts:31:14)
    at Generator.next (<anonymous>)
From previous event:
    at Object.done (C:\Users\me\Documents\projects\myapp\app\node_modules\electron-updater\src\BaseUpdater.ts:30:11)
    at C:\Users\me\Documents\projects\myapp\app\node_modules\electron-updater\src\AppUpdater.ts:552:25
    at Generator.next (<anonymous>)
    at runCallback (timers.js:781:20)
    at tryOnImmediate (timers.js:743:5)
    at processImmediate [as _immediateCallback] (timers.js:714:5)
From previous event:
    at done (C:\Users\me\Documents\projects\myapp\app\node_modules\electron-updater\src\AppUpdater.ts:546:15)
    at C:\Users\me\Documents\projects\myapp\app\node_modules\electron-updater\src\AppUpdater.ts:609:18
    at Generator.next (<anonymous>)
    at CB (C:\Users\me\Documents\projects\myapp\app\node_modules\graceful-fs\polyfills.js:112:17)
    at FSReqWrap.oncomplete (fs.js:135:15)
From previous event:
    at NsisUpdater.executeDownload (C:\Users\me\Documents\projects\myapp\app\node_modules\electron-updater\src\AppUpdater.ts:511:68)
    at NsisUpdater.executeDownload (C:\Users\me\Documents\projects\myapp\app\node_modules\electron-updater\src\BaseUpdater.ts:28:18)
    at NsisUpdater.doDownloadUpdate (C:\Users\me\Documents\projects\myapp\app\node_modules\electron-updater\src\NsisUpdater.ts:27:17)
    at NsisUpdater.downloadUpdate (C:\Users\me\Documents\projects\myapp\app\node_modules\electron-updater\src\AppUpdater.ts:411:19)
    at downloadUpdate (C:\Users\me\Documents\projects\myapp\app\backend\backendUpdater.js:63:17)
    at EventEmitter.ipcMain.on (C:\Users\me\Documents\projects\myapp\app\backend\backendUpdater.js:133:59)
    at emitTwo (events.js:125:13)
    at EventEmitter.emit (events.js:213:7)
    at WebContents.<anonymous> (C:\Users\me\Documents\projects\myapp\node_modules\electron\dist\resources\electron.asar\browser\api\web-contents.js:266:13)
    at emitTwo (events.js:125:13)
    at WebContents.emit (events.js:213:7)
Unhandled rejection TypeError: Cannot read property 'version' of undefined
    at NsisUpdater.autoUpdater.on (C:\Users\me\Documents\projects\myapp\app\backend\backendUpdater.js:103:106)
    at emitOne (events.js:115:13)
    at NsisUpdater.emit (events.js:210:7)
    at NsisUpdater.dispatchUpdateDownloaded (C:\Users\me\Documents\projects\myapp\app\node_modules\electron-updater\src\AppUpdater.ts:430:10)
    at Object.<anonymous> (C:\Users\me\Documents\projects\myapp\app\node_modules\electron-updater\src\BaseUpdater.ts:31:14)
    at Generator.next (<anonymous>)
From previous event:
    at Object.done (C:\Users\me\Documents\projects\myapp\app\node_modules\electron-updater\src\BaseUpdater.ts:30:11)
    at C:\Users\me\Documents\projects\myapp\app\node_modules\electron-updater\src\AppUpdater.ts:552:25
    at Generator.next (<anonymous>)
    at runCallback (timers.js:781:20)
    at tryOnImmediate (timers.js:743:5)
    at processImmediate [as _immediateCallback] (timers.js:714:5)
From previous event:
    at done (C:\Users\me\Documents\projects\myapp\app\node_modules\electron-updater\src\AppUpdater.ts:546:15)
    at C:\Users\me\Documents\projects\myapp\app\node_modules\electron-updater\src\AppUpdater.ts:609:18
    at Generator.next (<anonymous>)
    at CB (C:\Users\me\Documents\projects\myapp\app\node_modules\graceful-fs\polyfills.js:112:17)
    at FSReqWrap.oncomplete (fs.js:135:15)
From previous event:
    at NsisUpdater.executeDownload (C:\Users\me\Documents\projects\myapp\app\node_modules\electron-updater\src\AppUpdater.ts:511:68)
    at NsisUpdater.executeDownload (C:\Users\me\Documents\projects\myapp\app\node_modules\electron-updater\src\BaseUpdater.ts:28:18)
    at NsisUpdater.doDownloadUpdate (C:\Users\me\Documents\projects\myapp\app\node_modules\electron-updater\src\NsisUpdater.ts:27:17)
    at NsisUpdater.downloadUpdate (C:\Users\me\Documents\projects\myapp\app\node_modules\electron-updater\src\AppUpdater.ts:411:19)
    at downloadUpdate (C:\Users\me\Documents\projects\myapp\app\backend\backendUpdater.js:63:17)
    at EventEmitter.ipcMain.on (C:\Users\me\Documents\projects\myapp\app\backend\backendUpdater.js:133:59)
    at emitTwo (events.js:125:13)
    at EventEmitter.emit (events.js:213:7)
    at WebContents.<anonymous> (C:\Users\me\Documents\projects\myapp\node_modules\electron\dist\resources\electron.asar\browser\api\web-contents.js:266:13)
    at emitTwo (events.js:125:13)
    at WebContents.emit (events.js:213:7)
Done in 50.81s.

The referenced file backendUpdater.js:103:106 is as follows.

    autoUpdater.on('update-downloaded', () => {
        debug(`downloaded ${autoUpdater.updateInfo.version}`);
    });

Same code has worked with earlier versions of electron-builder and updateInfo.version should still be there according to docs so that shouldn't be the real issue.

Any ideas what might be going on? Really appriciate any help.

And thanks for the great tool and work you do @develar (and others).

JsseL commented 5 years ago

Ok, solved it. 🎯

Summary: 🐛

Our code:

    autoUpdater.on('update-downloaded', () => {
        debug(`downloaded ${autoUpdater.updateInfo.version}`);
    });

used to with "electron-updater": "^2.20.2", but after upgrading to "electron-updater": "3.2.3" that did not work anymore due to autoUpdater not having updateInfo attribute.

Solution 🏆

As the docs state, update-downloaded event passes the updateInfo object as parameter to the event handler.

So after we changed our code to:

    autoUpdater.on('update-downloaded', (updateInfo) => {
        debug(`downloaded ${updateInfo.version}`);
    });

things started to work again.