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.7k stars 1.74k forks source link

Unhandled rejection TypeError #3488

Closed gitliyu closed 6 years ago

gitliyu commented 6 years ago

electron 1.8.2 vue-electron 1.0.6 electron-updater 4.0.4

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();
  })
}
develar commented 6 years ago

electron 1.8.2

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

gitliyu commented 6 years ago

@develar Thanks a lot, the problem has been solved

mike-seekwell commented 5 years ago

@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 "asn1.js@4.10.1" is incompatible with requested version "asn1.js@^5.0.0"
├─ electron-builder-lib@20.19.2
├─ electron-builder@20.19.2
├─ electron-context-menu@0.9.1
├─ electron-debug@1.5.0
│  └─ electron-is-dev@0.3.0
├─ electron-dl@1.12.0
├─ electron-download@4.1.1
├─ electron-in-page-search@1.3.2
├─ electron-is-accelerator@0.1.2
├─ electron-is-dev@0.1.2
├─ electron-json-storage@3.2.0
├─ electron-localshortcut@3.1.0
├─ electron-osx-sign@0.4.10
├─ electron-publish@20.19.0
├─ electron-toolkit@1.0.24
├─ electron-unhandled@1.1.0
├─ electron-updater@4.0.5
├─ electron@3.0.10
├─ keyboardevent-from-electron-accelerator@1.1.0
└─ winston-electron@0.2.0

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)
zhaoterryy commented 5 years ago

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.

mike-seekwell commented 5 years ago

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()

lichunlovexyt commented 5 years ago

@develar Thanks a lot, the problem has been solved

please tell your methods,thanks