question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

"@electron/remote" cannot be required in the browser process. Instead require("@electron/remote/main").

See original GitHub issue

Hi, I am using electron 11.4.8 , operating System macos @electron/remote@1.1.0., build electron build work in development mode perfect but with electron-builder it shows me an error which is: Error: "@electron/remote" cannot be required in the browser process. Instead require("@electron/remote/main").

my index.js will execute in main process. index.js

const { join } = require("path");
require("@electron/remote/main").initialize(); // this will 

module.exports = {
  init: async () => {
    return {};
  },
  getRendererAppLocation: async () => {
    return `file://${join(__dirname, "..", "index.html")}`;
  },
  preload: async () => {
    console.log("preload path", join(__dirname, "preload.js"));
    // return join(__dirname, "preload.js"); // if i use this line the preload will not execute
    return __non_webpack_require__(join(__dirname, "..", "preload.js")); // if i use this line the preload will execute but with above error.
  },
};

preload.js

console.log("preload is executing");
const {dialog} = require("@electron/remote")
globalThis.dialog = dialog;
console.log("Debug dialog", globalThis.dialog);

in main process i do also require("@electron/remote/main").initialize();

can you please tell me what i do wrong ?

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:30
  • Comments:12

github_iconTop GitHub Comments

5reactions
aleksey-hoffmancommented, Aug 26, 2021

Try this:

const electron = require('electron')
const electronRemote = process.type === 'browser'
  ? electron
  : require('@electron/remote')
2reactions
aolyangcommented, Jan 19, 2022

I have a similar problem that log can not require @electron/remote/main. After deep look the bundle file, found the problem is @electron/remote module didn’t bundled into assets file, and mainProcess has no way to find it.

So, my resolution is simple, add @electron/remote to dependencies, add it to electorn-builder build config’s extraresources(copy files into dist/node_modules). then, require("@electron/remote/main") is working fine.

I didn’t sure is really can get help, but mention it here for a looking. 😄

Read more comments on GitHub >

github_iconTop Results From Across the Web

Electron.remote is undefined - node.js - Stack Overflow
Original answer: remote is needed only to require other modules from inside a render process. In the main process you just get your...
Read more >
@electron/remote - npm
electron /remote` is an [Electron](https://electronjs.org) module that bridges JavaScript objects from the main process to the renderer ...
Read more >
Breaking Changes | Electron
The remote module was deprecated in Electron 12, and will be removed in ... Another implication is that require() cannot be used in...
Read more >
require('electron')报错后使用最新方法引入remote - CSDN博客
若在渲染进程中使用main process需要通过remote模块。eletron14.0以下,使用以下引入const { BrowserWindow } = require('electron').remoteeletro.
Read more >
remote | Electron
With the remote module, you can invoke methods of the main process object without ... const {BrowserWindow} = require('electron').remote let win = new ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found