-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"@electron/remote" cannot be required in the browser process. Instead require("@electron/remote/main"). #66
Comments
it happened to me. Any solutions yet? |
Try this: const electron = require('electron')
const electronRemote = process.type === 'browser'
? electron
: require('@electron/remote') |
I'm having the same issue. @aleksey-hoffman This did not work for me.. |
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). I didn't sure is really can get help, but mention it here for a looking. 😄 |
@aolyang having the same issue, how does your extraresources config look like? |
Same issue. "extraResources": [
"./node_modules/@electron/remote/**"
], |
The error is that require('@electron/remote') must be called in the rendering process and not in the "main" file. For example, where you create the "BrowserWindow" you should import directly from electron:
But from the code that is part of the application's views, so to speak, you can access the API as follows:
I hope I explained myself as well as possible and that this was helpful. |
Yh, like @Unforgiven-wanda did. I made my build script, it has a little difference. But does the same thing. // a part of electron-builder config
extraResources: [
{
from: path.join(__dirname, "./node_modules/@electron/remote"),
to: path.join(__dirname, "./dist/node_modules/@electron/remote")
}
] In my build, I created a fake package.json for electron: const pkg = require("../package.json")
const pkgJson = `{
"name": "app",
"version": "${pkg.version}",
"author": "${pkg.author}",
"main": "./main/index.cjs",
"dependencies": {
"@electron/remote": "${pkg.dependencies["@electron/remote"]}"
},
"devDependencies": {
"electron": "${pkg.devDependencies.electron}"
}
}
` Before electron-builder build, I have the simple structure like this:
electron/remote#migrating-from-remote Main problem is electron only accept cjs format file, and this format(bundle tool behavior) will not auto pick and convert You can see the difference! cjs format, main process, file not exported cjs format preload file, use in renderer, file exported Mabe someone big can explain the detials. Hopefully helped! |
why is ok ? |
I am using electron-forge and already added the package ("@electron/remote"). Everything works fine when using
|
@akbayt if you are using the webpack plugin build, you can use a CopyWebpackPlugin to integrate it into your main, that seems to work fine:
|
Hi @YvanGuidoin, thanks for the suggestion. However, it turned out that the issue was different. I tried some plugins, but none of them worked. Then, I added the remote package to dependencies instead of devDependencies. This is supposed to be enough but my forge config was implicitly ignoring the So:
finally |
Hi, I am using electron 11.4.8 , operating System macos @electron/[email protected]., 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
preload.js
in main process i do also
require("@electron/remote/main").initialize();
can you please tell me what i do wrong ?
The text was updated successfully, but these errors were encountered: