Electron-builder: Unhandled rejection TypeError

Created on 19 Nov 2018  ยท  6Comments  ยท  Source: electron-userland/electron-builder


  • Version: 20.36.2


electron 1.8.2
vue-electron 1.0.6
electron-updater 4.0.4

  • Target: windows


Hi, I'm using the latest version of electron-updater, when I call the method autoUpdater.checkForUpdates, get the following error

Unhandled rejection TypeError: this.app.whenReady is not a function
      at ElectronAppAdapter.whenReady (E:\projects\cages-pos-client\node_modules\electron-updater\src\ElectronAppAdapter.ts:9:21)
      at E:\projects\cages-pos-client\node_modules\electron-updater\src\AppUpdater.ts:337:20
      at Generator.next (<anonymous>)
  From previous event:
      at NsisUpdater.getUpdateInfoAndProvider (E:\projects\cages-pos-client\node_modules\electron-updater\src\AppUpdater.ts:336:43)
      at E:\projects\cages-pos-client\node_modules\electron-updater\src\AppUpdater.ts:363:31
      at Generator.next (<anonymous>)
  From previous event:
      at NsisUpdater.doCheckForUpdates (E:\projects\cages-pos-client\node_modules\electron-updater\src\AppUpdater.ts:360:34)
      at NsisUpdater.checkForUpdates (E:\projects\cages-pos-client\node_modules\electron-updater\src\AppUpdater.ts:220:35)
      at EventEmitter.<anonymous> (E:\projects\cages-pos-client\dist\electron\main.js:2663:67)
      at emitOne (events.js:115:13)
      at EventEmitter.emit (events.js:210:7)
      at WebContents.<anonymous> (E:\projects\cages-pos-client\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)

This is part of my main.js

import {app, globalShortcut, BrowserWindow, ipcMain} from 'electron';
import {autoUpdater} from 'electron-updater';

if (process.env.NODE_ENV !== 'development') {
  global.__static = require('path').join(__dirname, '/static').replace(/\\/g, '\\\\')
}

let mainWindow;
const winURL = process.env.NODE_ENV === 'development'
  ? `http://localhost:9080`
  : `file://${__dirname}/index.html`;

function createWindow () {
  mainWindow = new BrowserWindow({
    height: 768,
    width: 1024,
    autoHideMenuBar: true,
    webPreferences: {
      webSecurity: false
    }
  });

  mainWindow.loadURL(winURL)

  mainWindow.on('closed', () => {
    mainWindow = null
  });

  updateHandle();
}

app.on('ready', createWindow);

app.on('window-all-closed', () => {
  if (process.platform !== 'darwin') {
    app.quit()
  }
});

app.on('activate', () => {
  if (mainWindow === null) {
    createWindow()
  }
});

function updateHandle () {
  autoUpdater.setFeedURL('path');
  autoUpdater.on('error', function () {
    mainWindow.webContents.send('message', 'error')
  });
  autoUpdater.on('checking-for-update', function () {
    mainWindow.webContents.send('message', 'checking')
  });
  autoUpdater.on('update-available', function () {
    mainWindow.webContents.send('message', 'update')
  });
  autoUpdater.on('update-not-available', function () {
    mainWindow.webContents.send('message', 'is_new')
  });

  autoUpdater.on('update-downloaded', function () {
    ipcMain.on('isUpdateNow', () => {
      autoUpdater.quitAndInstall();
    });
    mainWindow.webContents.send('isUpdateNow')
  });

  ipcMain.on('update-version', () => {
    autoUpdater.checkForUpdates();
  })
}

electron-updater question

Most helpful comment

@develar Thanks a lot, the problem has been solved

All 6 comments

electron 1.8.2

Please use Electron 3.x (it is stable release).

@develar Thanks a lot, the problem has been solved

@develar I'm still getting the error using the below versions on Mac (haven't tested Windows). It worked fine with "electron-updater": "^3.1.2" and "electron": "~1.7.11"

yarn list --pattern electron
yarn list v1.9.4
warning Resolution field "[email protected]" is incompatible with requested version "asn1.js@^5.0.0"
โ”œโ”€ [email protected]
โ”œโ”€ [email protected]
โ”œโ”€ [email protected]
โ”œโ”€ [email protected]
โ”‚  โ””โ”€ [email protected]
โ”œโ”€ [email protected]
โ”œโ”€ [email protected]
โ”œโ”€ [email protected]
โ”œโ”€ [email protected]
โ”œโ”€ [email protected]
โ”œโ”€ [email protected]
โ”œโ”€ [email protected]
โ”œโ”€ [email protected]
โ”œโ”€ [email protected]
โ”œโ”€ [email protected]
โ”œโ”€ [email protected]
โ”œโ”€ [email protected]
โ”œโ”€ [email protected]
โ”œโ”€ [email protected]
โ””โ”€ [email protected]





Unhandled Promise Rejection
TypeError: this.app.whenReady is not a function
    at ElectronAppAdapter.whenReady (/Users/mritchie712/seekwell/desktop/node_modules/electron-updater/src/ElectronAppAdapter.ts:9:21)
    at /Users/mritchie712/seekwell/desktop/node_modules/electron-updater/src/AppUpdater.ts:337:20
    at Generator.next (<anonymous>)
From previous event:
    at MacUpdater.getUpdateInfoAndProvider (/Users/mritchie712/seekwell/desktop/node_modules/electron-updater/src/AppUpdater.ts:336:43)
    at /Users/mritchie712/seekwell/desktop/node_modules/electron-updater/src/AppUpdater.ts:363:31
    at Generator.next (<anonymous>)
From previous event:
    at MacUpdater.doCheckForUpdates (/Users/mritchie712/seekwell/desktop/node_modules/electron-updater/src/AppUpdater.ts:360:34)
    at MacUpdater.checkForUpdates (/Users/mritchie712/seekwell/desktop/node_modules/electron-updater/src/AppUpdater.ts:220:35)
    at App.createWindow (/Users/mritchie712/seekwell/desktop/main.js:1335:15)

That is strange, what do you get when you run node_modules/electron/dist/Electron.app/Contents/MacOS/Electron -v?

Other than that I suggest you delete your node_modules directory and run yarn again.

Thanks for following up, I realized the problem was with how I was calling checkForUpdates, I needed to do this:

app.on('ready', function()  {
  createWindow()
  backgroundWindow = createBackgroundWindow()
  if (targetEnv == 'prod') {
    autoUpdater.checkForUpdates();
  }
});

instead of:

app.on('ready', createWindow)

Where I had autoUpdater.checkForUpdates(); as part of createWindow()

@develar Thanks a lot, the problem has been solved

please tell your methods,thanks

Was this page helpful?
0 / 5 - 0 ratings

Related issues

iklemm picture iklemm  ยท  3Comments

jhg picture jhg  ยท  3Comments

antonycourtney picture antonycourtney  ยท  3Comments

omarkilani picture omarkilani  ยท  3Comments

leo picture leo  ยท  3Comments