Skip to content
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

TypeError: Cannot read properties of undefined (reading 'members') #79

Closed
FedeIlLeone opened this issue Sep 15, 2021 · 9 comments
Closed

Comments

@FedeIlLeone
Copy link
Contributor

FedeIlLeone commented Sep 15, 2021

After upgrade to remote v2.0.1 (electron v14.0.1) I can't use the remote module in the renderer process.
The line and where the error comes from the renderer file:

const { dialog } = require("@electron/remote");

Main process:

const { app, BrowserWindow } = require("electron");
const remoteMain = require("@electron/remote/main");
const win = new BrowserWindow({ ... });
remoteMain.enable(win.webContents);
win.loadFile("./build/web/index.html");

Everything was working fine before the upgrade.

@Nashorn
Copy link

Nashorn commented Sep 16, 2021

Upgraded to v14.0.0, added the @electron/remote npm to dependencies:
"devDependencies": {
"electron": "14.0.0",
"@electron/remote": "2.0.1"
}

The previous working code no longer works:
app.getPath("documents")

ERROR:
Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'members')

I've tried both ways:
let { app } = require('@electron/remote');
const userDataPath = app.getPath('documents');

and:
let { app } = require('@electron/remote/main');

@SimplyViper16
Copy link

SimplyViper16 commented Sep 16, 2021

Hello guys!
Maybe I've found the solution! I was facing the same issue and I've tried a thing...

On the migration doc (https://github.com/electron/remote/blob/main/docs/migration-2.md) none mention the required line of the previous major version:

require('@electron/remote/main').initialize()

I've deleted that on the main process cause I was thinking that was not required anymore.
Well, I was wrong. I've restore that line and everything is working fine now.

I use the code from @FedeIlLeone for give you an example.

Main process:

const { app, BrowserWindow } = require("electron");
const remoteMain = require("@electron/remote/main");

/* add this before the enable function */
remoteMain.initialize();

const win = new BrowserWindow({ ... });
remoteMain.enable(win.webContents);
win.loadFile("./build/web/index.html");

I hope that can help you all!
Valentina

@FedeIlLeone
Copy link
Contributor Author

Thank you! That fixed the issue.

On the migration doc (https://github.com/electron/remote/blob/main/docs/migration-2.md) none mention the required line of the previous major version

I think it should be written that you have to use .initialize() in v2 too.

@Nashorn
Copy link

Nashorn commented Sep 17, 2021

That worked! Thank you 👍

@Nashorn
Copy link

Nashorn commented Sep 17, 2021

Doc should also mention needing the remote npm dependency:
"devDependencies": {
"electron": "14.0.0",
"@electron/remote": "2.0.1"
}

@itsUndefined
Copy link

Documentation is still not clear enough that you need both the initialize and the enable. I had to search the closed issues on github to realize my mistake.

@pranavwani
Copy link

@itsUndefined both are required with electron v16 and remote module @2.x as mentioned in the doc https://github.com/electron/remote/blob/main/docs/migration-2.md

Thanks, @Valentina16 it works perfectly

@hatton
Copy link

hatton commented Oct 2, 2022

For me, after carefully doing the above, remote was still undefined in the render process. My error was dumb:

import remote from "@electron/remote";

Instead, I needed
import * as remote from "@electron/remote";

or
const remote require("@electron/remote")

Normally the typescript type system would squawk at a problem like this, so maybe this is just something weird in my setup.

@Rabbitzzc
Copy link
Contributor

electron/electron#37067

cblgh added a commit to cabal-club/cabal-desktop that referenced this issue Dec 6, 2023
"In Electron 9, using the remote module without explicitly enabling it via the enableRemoteModule WebPreferences option began emitting a warning. In Electron 10, the remote module is now disabled by default. To use the remote module, enableRemoteModule: true must be specified in WebPreferences:"

https://github.com/electron/electron/blob/main/docs/breaking-changes.md#default-changed-enableremotemodule-defaults-to-false

if migrating to larger versions, in particular for electron-store@2 see the following links

https://stackoverflow.com/questions/55850616/uncaught-referenceerror-module-is-not-defined-on-delete-module-exports
electron/remote#79
https://github.com/electron/remote/blob/main/docs/migration-2.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants