Reputation: 1370
I’m using React with Webpack and Electron and I’m trying to require the remote from the renderer process. My code is being transpired by Babel + Webpack but this line of code:
import {remote} from 'electron'
is giving me
Uncaught Error: Cannot find module "electron"
How can I fix this? I know that the issue is because electron injects the electron module on the rendering of the page which webpack doesn’t know about it.
const {remote} = window.require('electron')
Works fine because it’s ignored by webpack.
Upvotes: 1
Views: 1934
Reputation: 74
If you are using a recent version of webpack, set the target property to electron-renderer
in the renderer configuration.
module.exports = {
target: 'electron-renderer',
//... other configurations
}
If you are using webpack to bundle main(main.js), set the target property to electron-main
in the main configuration.
module.exports = {
target: 'electron-main',
//... other configurations
}
Upvotes: 1