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

Cannot read property 'app' of undefined #133

Closed
theArina opened this issue Sep 16, 2020 · 15 comments
Closed

Cannot read property 'app' of undefined #133

theArina opened this issue Sep 16, 2020 · 15 comments

Comments

@theArina
Copy link

theArina commented Sep 16, 2020

Electron version: 10.0.0
Electron-settings version: 4.0.2
Platform: Windows 10

This function of the source depends on the "remote" module which is deprecated. In the new versions of the Electron it will be removed afaik.

 * Returns the Electron app. The app may need be accessed
 * via `Remote` depending on whether this code is running
 * in the main or renderer process.
 *
 * @returns The Electron app.
 * @internal
 */
function getElectronApp() {
    var _a;
    var e = getElectron();
    var app = (_a = e.app) !== null && _a !== void 0 ? _a : e.remote.app;
    return app;
}
@mathieupothier
Copy link

I have the same issue on electron 10.x
Using 9.x works for now as a workaround

@theArina
Copy link
Author

@mathieupothier, have you tried to set the enableRemoteModule to true in 10x? as a workaround. cause i tried this just now, but it doesn't seems to work, that's weird.

@mathieupothier
Copy link

I tested it in the past and it did not work back then. Got to try it again since you asked and I spotted an error on my end.

The enableRemoteModule: true needs to be in webPreferences: {}

Was:
new BrowserWindow({ enableRemoteModule: true });

Needed to be:
new BrowserWindow({ webPreferences: { enableRemoteModule: true }});

Now it works perfectly. So unless it's the same for you, it seems to be working with the flag properly set.

@theArina
Copy link
Author

@mathieupothier, yes, thank you for the tip. It works for me too with the flag inside webPreferences.
Might make a fork later to avoid using remote at all though.

@ckissi
Copy link

ckissi commented Sep 30, 2020

I tested it in the past and it did not work back then. Got to try it again since you asked and I spotted an error on my end.

The enableRemoteModule: true needs to be in webPreferences: {}

Was:
new BrowserWindow({ enableRemoteModule: true });

Needed to be:
new BrowserWindow({ webPreferences: { enableRemoteModule: true }});

Now it works perfectly. So unless it's the same for you, it seems to be working with the flag properly set.

thanks. It works!

@nathanbuchar
Copy link
Owner

Hey thanks for the solution! I'll add this to the README.

@theArina
Copy link
Author

theArina commented Oct 2, 2020

@nathanbuchar, no no no no, this is not a solution, this is a crutch.
well, i made a fork to avoid using the 'remote' module. it's kinda raw, but i still could make a pull request, would you like me to ?

@nathanbuchar
Copy link
Owner

Sorry, I misunderstood when glancing through this issue. Yes that would be very helpful, thank you!

@ThibaultJousse
Copy link

Hi @nathanbuchar,
is there any update regarding the PR ? We're using electron-settings in a school project where we'll need to set enableRemoteModule to false.
Should we wait for a new release or try to use an other module ?

@nathanbuchar
Copy link
Owner

nathanbuchar commented Nov 16, 2020

@ThibaultJousse thanks for bumping this. It's always been in the back of my mind, just haven't gotten around to it, for really no good reason :) I'll take care of this right now

@nathanbuchar
Copy link
Owner

nathanbuchar commented Nov 18, 2020

After looking at the PR the other day, I learned that this fix is a bit more involved than I was originally expecting. Will in to dig in a bit more this weekend, sorry about that!

@dmitrif
Copy link

dmitrif commented Nov 27, 2021

Hi there! Just wanted to follow up on this.

@TechStudent10
Copy link

Hey! I know it's been a year but I just want to say that using the remote module is a huge security risk. You should instead use ipcMain, ipcRender, and contextBridge to send in the renderer process and receive in the main process.

Relevant links:

@nathanbuchar
Copy link
Owner

I appreciate you bumping this, however I have not used Electron in years. I'd highly recommend submitting a PR, as it's unlikely I will address this anytime soon

@TechStudent10
Copy link

I appreciate you bumping this, however I have not used Electron in years. I'd highly recommend submitting a PR, as it's unlikely I will address this anytime soon

Sure! I'll submit a PR later to address this in the README.

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