electron-next
electron-next copied to clipboard
Unable to use electron from renderer
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).
did you find any solution?
Nope. @leo , sorry for tagging but did you had a similar problem before ?
@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!