What this thread does
Do first: keep webPreferences.nodeIntegration: false and set webPreferences.preload to the absolute path of the preload that exposes your narrow bridge.
Short answer
As of November 2026, Electron 45.4.1 retains isolated renderer/preload contexts. require is not defined. Move the native operation behind preload/main IPC (isolation); do not grant arbitrary Node access to repair it.
Diagnostic: require is not defined
Pabatribick's April 4, 2021 issue records a renderer failure and maintainer guidance toward preload. Identify the JavaScript context that emitted the error first.
Choose / don't choose
- Dedicated
ipcRenderer.invoke()wrapper: choose for a specific native action, with one fixed channel per method; don't let the page select arbitrary channels (isolation). - Main-process implementation: choose for filesystem/native modules unavailable inside sandboxed preload; validate the sender and arguments at the privileged boundary (security).
Not for: porting Electron distribution to Tauri; see electron-to-tauri-2-migration-with-signed-auto-updates.
Settings that matter
| Setting or flag | Value / default | Applies to | Source |
|---|---|---|---|
webPreferences.preload | Absolute script path, loaded before page scripts | Current Electron window docs | window |
webPreferences.contextIsolation | true; default since Electron 12 | Current Electron; documented boundary | isolation |
webPreferences.nodeIntegration | false; enabling it disables the renderer sandbox | Current Electron | window, sandbox |
webPreferences.sandbox | true, default since Electron 20; preload require is restricted | Current Electron; documented boundary | sandbox |
contextBridge.exposeInMainWorld | Small named object, e.g. loadPreferences wrapping the fixed load-prefs channel | Current Electron bridge pattern | bridge pattern |
Order of operations
1. Set the actual BrowserWindow's preload before loading the page. Confirm its absolute path exists in the packaged app (window). 2. In preload use the documented bridge pattern:
const { contextBridge, ipcRenderer } = require('electron');
contextBridge.exposeInMainWorld('electronAPI', {
loadPreferences: () => ipcRenderer.invoke('load-prefs')
});
3. Register the corresponding main-process ipcMain.handle handler, validating sender and arguments. The fixed channel follows the official bridge example; main-side invocation uses ipcMain.handle. 4. Inspect preload errors and the bridge property in the page context. Exercise the permitted operation and invalid arguments. A TypeScript Window declaration supplies types (isolation).
Known failures and fixes
| Error (short quote) | Cause | Fix | Source |
|---|
| Bridge property undefined (symptom) | Direct preload window assignment is invisible to page | Use contextBridge; inspect preload load errors and path | isolation, window | | Preload cannot require dependency (symptom) | Sandboxed require lacks general CommonJS loading | Bundle compatible helpers; move privileged modules to main | sandbox |
Electron 29+ forbids passing ipcRenderer itself across the bridge (API history); dedicated wrappers also restrict channel access. Current sandboxed preload can require only electron and its documented aliases; Node built-in modules are unavailable (sandbox).
Missing
- Main-handler authorization and argument schema depend on the native action. The bridge alone does not secure an IPC endpoint.
- The linked source does not confirm: a general Node/Electron-import cause for renderer require failures; the specific page-side loadPreferences call on the IPC reference page.
Checked
2026-11-24; Electron release, window/isolation/sandbox/contextBridge/IPC/security references and historical renderer issue read. No Electron commands executed.
Started from a post by @Electron contributors, packaged by the editor. Original post