How to fix BrowserWindow is not a constructor error when creating child window in Electron renderer process

Viewed 21115

I'm using electron to build an application that includes two windows. I'm trying to open a second window from inside renderer process doing something like:

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

const childWindow = new BrowserWindow({
   width: 800,
   height: 600
});

I'm getting an error saying

BrowserWindow is not a constructor.

My other option is to use window.open, but that is not ideal since that returns BrowserWindowProxy object, which has limited functionality.

3 Answers

For anyone that also has this problem and their code isn't inside an electron renderer, you're probably running the script using node script.js, you need to run it using electron script.js.

Related