-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
remote
does not exist when app is launched without Electron run-time
#58
Comments
describe repro |
Sample code taken from Electron docs : const { app, BrowserWindow } = require('electron')
const openAboutWindow = require('about-window')
function createWindow () {
let win = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
nodeIntegration: true
}
})
// and load the index.html of the app.
win.loadFile('index.html')
}
if (app) app.whenReady().then(createWindow);
// Do something else with the app that doesn't require electron
console.log('Yeah'); Here The problem is that requiring about-window executes the top-level code of the module, which assumes electron is loaded, and thus crashes the main app with an exception. Hope that helps. |
Thanks for the code. So minimal steps are:
const openAboutWindow = require('about-window')
This package does not support the usage without Electron. Though I'm still not sure to understand the situation, if you want to write up code which supports both Electron and Node.js, you would need to write code like below: const { app, BrowserWindow } = require('electron')
function createWindow () {
// Run only on Electron
const openAboutWindow = require('about-window')
let win = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
nodeIntegration: true
}
})
// and load the index.html of the app.
win.loadFile('index.html')
}
if (app) app.whenReady().then(createWindow);
// Do something else with the app that doesn't require electron
console.log('Yeah');
|
I used require for the example with JS, but I'm using import (via typescript) and imports are not conditionnal, they're loaded up no matter what, hence my request. Version 1.13.2 worked just fine, the bug was introduced in 1.13.3 with the call to |
I fixed this in 1.13.4. Please update to the latest |
Thanks for the quick fix! That works just fine :) |
Hello.
I upgraded to the latest version of about-window (1.13.3) but it broke my app during its CI.
Since it's an electron app, we also have a mode to run it without the electron runtime, namely for debug purposes and launch in CI (since the app can also do some CLI stuff)
When not loaded via the Electron runtime, the
app
andremote
objects are undefined. This is normally not a problem as in my own application I test if app is defined before doing anything with it.However, on line 5 of index.ts the code tries to get
remote.app
except that since remote is undefined, it crashes my application on startup when importing, since the code is at the top level of the module and is executed, wether electron is loaded or not.A quick fix would be to test if remote exists as well before trying to use
remote.app
or if you're using a recent typescript, an optional chaining likeremote?.app
which works wonders in those cases.For now I pinned my version of about-window to 1.13.2 while waiting for a fix :)
Thanks in advance.
The text was updated successfully, but these errors were encountered: