npmnode.js95% confidence\u2191 77

Electron.remote is undefined

Full error message
I have trouble with using Electron. As you can see the title, when i load remote module, it saids it is undefined. This is the code of entry js:

const electron = require('electron');
const { app, BrowserWindow, Tray, remote, ipcMain } = electron;

function initApp() { ... }

app.on('ready', () => {
    initApp();

    console.log(electron);         // object, but no remote inside
    console.log(electron.remote);  // undefined
    console.log(remote);           // undefined
});

and i tried to follow official doc here: http://electron.atom.io/docs/api/remote/

with

const { remote } = electron;
const { BrowserWindow } = remote;

let win = new BrowserWindow({width: 800, height: 600});  // error! BrowserWindow is not a constructor blabla

...
remote.getCurrentWindow().focus();

i don't know what am i missing. any advice will very appreciate.

Update 2020, since this answer still appears at the top. For the original answer to work in current versions of Electron, you need to set enableRemoteModule when creating the window in your main process. const myWindow = new BrowserWindow({ webPreferences: { enableRemoteModule: true } }); Original answer: remote is needed only to require other modules from inside a render process. In the main process you just get your modules directly from require('electron'). Which it looks like is done in the example just with remote unnecessarily added. Render process: const { remote } = require('electron'); const { BrowserWindow } = remote; Main process: const { BrowserWindow } = require('electron');

API access

Get this solution programmatically \u2014 free, no authentication.

curl https://depscope.dev/api/error/622ba44aea838da8473d545e0e764c4f0fb318fafa5dbaed3d3a36158753e4dd
hash \u00b7 622ba44aea838da8473d545e0e764c4f0fb318fafa5dbaed3d3a36158753e4dd
Electron.remote is undefined — DepScope fix | DepScope