require('electron').remote returns undefined in the renderer
Fix it fast
Most common cause, 1 of 2Electron 14 or later has no built-in remote module
Do the work in the main process and expose one narrow function to the page.
// main.js
const { app, BrowserWindow, ipcMain, dialog } = require('electron');
const path = require('node:path');
async function handleFileOpen() {
const { canceled, filePaths } = await dialog.showOpenDialog();
if (!canceled) return filePaths[0];
}
app.whenReady().then(() => {
ipcMain.handle('dialog:openFile', handleFileOpen);
const win = new BrowserWindow({
webPreferences: { preload: path.join(__dirname, 'preload.js') },
});
win.loadFile('index.html');
});
// preload.js
const { contextBridge, ipcRenderer } = require('electron');
contextBridge.exposeInMainWorld('electronAPI', {
openFile: () => ipcRenderer.invoke('dialog:openFile'),
});
// renderer.js (replaces remote.dialog.showOpenDialog)
const filePath = await window.electronAPI.openFile();Short answer
require('electron').remote is undefined because Electron removed the built-in remote module in version 14, after turning it off by default in 10 and deprecating it in 12. On Electron 14 to 45, move the work into the main process and call it from the renderer with ipcRenderer.invoke through a preload script, or switch to the @electron/remote package.
Which cause do you have?
Print the Electron version the project installs and find every place that reaches for remote. An Electron of 14 or later with require('electron').remote in the code is cause 1; a hit on '@electron/remote' that then reads .remote is cause 2.
npm ls electron @electron/remote
grep -rnE "\.remote|\{[^}]*remote[^}]*\} *= *require\('electron'\)|@electron/remote" srcThen find the line you see in this list and open its fix:
- 1Electron 14 or later has no built-in remote module
npm ls shows electron 14.0.0 or higher, and the code still reads remote from the electron module, either as require('electron').remote or as const { remote } = require('electron') - 2The code uses @electron/remote but still reads a .remote property
The undefined value comes from require('@electron/remote').remote or from const { remote } = require('@electron/remote')
What does the error look like?
electron.remote is undefinedTypeError: Cannot read properties of undefined (reading 'BrowserWindow')TypeError: Cannot read properties of undefined (reading 'dialog')
Cause 1 of 2
Electron 14 or later has no built-in remote module
You seenpm ls shows electron 14.0.0 or higher, and the code still reads remote from the electron module, either as require('electron').remote or as const { remote } = require('electron')
Check
Electron's breaking-changes list records that the remote module was deprecated in Electron 12 and removed in Electron 14, so on any current release the remote property of the electron module is simply undefined. The first property read on it, such as remote.dialog or remote.BrowserWindow, throws Cannot read properties of undefined. On 10 to 13 it was present but disabled unless enableRemoteModule was true, which is why older answers suggest that flag.
grep -rnE "require\('electron'\)\.remote|\{[^}]*remote[^}]*\} *= *require\('electron'\)" srcFix
Do the work in the main process and expose one narrow function to the page. The main process registers a handler with ipcMain.handle, the preload script exposes a wrapper with contextBridge, and the renderer awaits it. Electron's IPC guide recommends ipcRenderer.invoke for this two-way pattern and advises against exposing the whole ipcRenderer object.
// main.js
const { app, BrowserWindow, ipcMain, dialog } = require('electron');
const path = require('node:path');
async function handleFileOpen() {
const { canceled, filePaths } = await dialog.showOpenDialog();
if (!canceled) return filePaths[0];
}
app.whenReady().then(() => {
ipcMain.handle('dialog:openFile', handleFileOpen);
const win = new BrowserWindow({
webPreferences: { preload: path.join(__dirname, 'preload.js') },
});
win.loadFile('index.html');
});
// preload.js
const { contextBridge, ipcRenderer } = require('electron');
contextBridge.exposeInMainWorld('electronAPI', {
openFile: () => ipcRenderer.invoke('dialog:openFile'),
});
// renderer.js (replaces remote.dialog.showOpenDialog)
const filePath = await window.electronAPI.openFile();Verify
Start the app the way the project normally does and trigger the action. The file dialog opens, and the renderer console shows the chosen path with no TypeError.
npm startConfirmed by electronjs.org
Cause 2 of 2
The code uses @electron/remote but still reads a .remote property
You seeThe undefined value comes from require('@electron/remote').remote or from const { remote } = require('@electron/remote')
Check
The @electron/remote package is itself the replacement object: its README swaps require('electron').remote for require('@electron/remote') and takes BrowserWindow straight from it. Code that was converted halfway asks that module for a remote property, which it does not have, so the result is undefined again. The package also needs Electron 13 or newer and two setup calls in the main process.
grep -rnE "require\('@electron/remote'\)\.remote|\{ *remote *\} *= *require\('@electron/remote'\)" srcFix
Import the members from the package directly. In the main process, call initialize() once and enable() for each window's webContents, as the README requires on Electron 14 and later. The README also warns that remote has many subtle pitfalls, so treat it as a bridge while you move calls to IPC.
// renderer or preload code that already loads packages with require
const { dialog, BrowserWindow } = require('@electron/remote');
// main.js
require('@electron/remote/main').initialize();
const win = new BrowserWindow();
require('@electron/remote/main').enable(win.webContents);Verify
In the renderer DevTools console, the imported dialog object is defined and its methods can be called.
npm ls @electron/remoteConfirmed by github.com
How do I stop it coming back?
- Read Electron's breaking-changes page before every major upgrade; the remote removal, the contextIsolation default in 12 and sandboxed renderers in 20 each changed what renderer code is allowed to do.
- Give each privileged action its own ipcMain.handle channel and expose only that wrapper from the preload, so no renderer depends on remote at all.
- Pin the electron version in package.json and upgrade one major at a time, running the app's main flows after each step.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.