Electron-builder: Cannot read property 'isReady' of undefined

Created on 20 Mar 2017  Â·  13Comments  Â·  Source: electron-userland/electron-builder

"electron-updater": "^1.10.4",
"electron-builder": "^15.5.1",
"electron-prebuilt": "^1.4.13"

targeting Windows

The issue is I am trying to use the script provided for the manual update in a sample application I am putting together and I am getting an error:

C:_projects\ElectronDemonode_modules\electron-updater\out\AppUpdater.js:122 Error: TypeError: Cannot read property 'isReady' of undefined
at AppUpdater.untilAppReady.default.resolve (C:_projects\ElectronDemonode_modules\electron-updater\src\AppUpdater.ts:81:18)

looking at the code for AppUpdater.ts it would appear the issues is around the following code:

else {
  this.app = require("electron").app
  executorHolder.httpExecutor = new ElectronHttpExecutor()
  this.untilAppReady = new BluebirdPromise(resolve => {
    if (this.app.isReady()) {

this is lines 77-81. Why would this.app = require("electron").app return a null? is this the real problem? Given this is the code that is part of the dependency and not something I created/modified, I am thinking I am missing something in my own code. I did not modify the code in the updater except to make the callback function not take any parameters and only call to checkforupdates()

function checkForUpdates () {
autoUpdater.checkForUpdates()
}

electron-updater question

Most helpful comment

@vjpudelski Your problem is that you are requiring updater.js from your index.html. And updater.js is then requiring electron-updater. The thing is to access electron components from a renderer process (updater.js), you need to use require('electron').remote, not require('electron').

Internally, electron-updater is calling just require('electron'). Therefore require("electron").app is undefined, as it should be require("electron").remote.app.

To fix this, please require updater.js from your actual electron application and use ipc calls to communicate between the main and renderer processes about when to check for updates, when updates are available, etc.

Also, I can see in your code that you have no check to stop auto updater from running in dev. Consider adding this check that develar mentioned: https://github.com/develar/onshape-desktop-shell/blob/master/src/AppUpdater.ts#L8 As electron-updater will not work in dev.

@develar Internally auto updater could fall back on remote if app is undefined? Not sure if we want to support that behavior as we also use electron components such as autoUpdater which might be susceptible to similar issues

All 13 comments

changed dependency to "electron": "1.4.15" and still have this error. I didn't realize that electron-prebuilt was an old way of doing it. I am also tying to 1.4.15 at this time due to using Electron-edge.

electron-updater should be not used in a dev mode.

I have the electron-updater in the dependencies and not the devDependencies. I am getting this error even upon building and installing the application on the machine.

@vjpudelski That's really strange.

Could you please send me app in a distributable format (dmg, zip) and I will check?

app.zip

very simple application just trying to get the update piece working. I even removed the distraction of the edge piece.

@develar have you had time to look at the zip? any thoughts? I am really just looking to prove the concept of the updates in this simple application before we move ahead with product development using the platform.

@vjpudelski Your problem is that you are requiring updater.js from your index.html. And updater.js is then requiring electron-updater. The thing is to access electron components from a renderer process (updater.js), you need to use require('electron').remote, not require('electron').

Internally, electron-updater is calling just require('electron'). Therefore require("electron").app is undefined, as it should be require("electron").remote.app.

To fix this, please require updater.js from your actual electron application and use ipc calls to communicate between the main and renderer processes about when to check for updates, when updates are available, etc.

Also, I can see in your code that you have no check to stop auto updater from running in dev. Consider adding this check that develar mentioned: https://github.com/develar/onshape-desktop-shell/blob/master/src/AppUpdater.ts#L8 As electron-updater will not work in dev.

@develar Internally auto updater could fall back on remote if app is undefined? Not sure if we want to support that behavior as we also use electron components such as autoUpdater which might be susceptible to similar issues

@AlienHoboken THANK YOU!

So I changed the index.html file to implement the ipcRenderer and the main file is now requiring updater.js and using ipcMain to listen for the event. This seems to work no problem. I will work on adding the proper checks and so forth to my code. As I said this is just a proof of concept so this is definitely not my cleanest code.

Now in terms of the IPC, is this a best practice? I will be sure to do further research on it but appreciate any insight and pointers.

IPC is the best practice for electron apps where you need to communicate between the render and main processes. You can use it to emit events or just general broadcast messages.

@AlienHoboken It was rejected — https://github.com/electron-userland/electron-builder/pull/962 "spawn/download should be executed in the main process"

I will add check to throw clear error for user.

Was this page helpful?
0 / 5 - 0 ratings