TypeError when defining `app`


In a tutorial i’m following, they use the following code:

const electron = require('electron');
const app = electron.app;
const BrowserWindow = electron.BrowserWindow;

If I try this in my own app, I get a TypeError: cannot read property 'on' of undefined when running app.on('ready', createWindow);

I found the following code when searching for a solution:

const electron = require('electron');
const app = require('app');
const BrowserWindow = require('browser-window')

The above code seems to work fine in my own app. So which way is correct, and why does the first example not work in my own app?


Looks like you’re using an older version of Electron. The code in the tutorial is the current way of accessing Electron APIs.


Looks like it was a conflict between my globally installed electron and a local version that was getting installed.