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

Unable to use electron from renderer #28

Open
Djiit opened this issue Apr 8, 2020 · 3 comments
Open

Unable to use electron from renderer #28

Djiit opened this issue Apr 8, 2020 · 3 comments

Comments

@Djiit
Copy link

Djiit commented Apr 8, 2020

Hi,

When importing electron for the renderer :

import electron from "electron";

I get this error :

Module not found: Can't resolve 'fs' 

Did I miss something in the config ?

I checked an old issue that suggested to use target="electron-target" but its outdated. Also, the now-desktop app doesn't use electron in the renderer (e.g. for opening links in default browser).

@anktsrkr
Copy link

did you find any solution?

@Djiit
Copy link
Author

Djiit commented Apr 26, 2020

Nope. @leo , sorry for tagging but did you had a similar problem before ?

@anktsrkr
Copy link

anktsrkr commented Apr 26, 2020

@Djiit Since nodeIntegration is disabled, we will not be able to use 'electron' package directly, However you can use any module of electron by exposing it in global.

This is how ipcRenderer is also exposed to renderer process.

Example -
Let's say you want to use remote.getCurrentWindow()

Goto preload.js and add these line -

const { ipcRenderer,remote} = require('electron')
process.once('loaded', () => {
  global.ipcRenderer = ipcRenderer,
  global.remote = remote
})

and from renderer process you can use like this - global.remote.getCurrentWindow()

i just figured, hope this helps!

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

2 participants