TypeError when defining `app`


#1

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?


#2

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


#3

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

Thanks!