Accepted answer

Webpack tries to resolve electron module with the installed node_modules. But the electron module is resolved in Electron itself at runtime. So, you have to exclude particular module from webpack bundling like this:


module.exports = {
  entry: './app.jsx',
  output: {
    path: './built',
    filename: 'app.js'
  target: 'atom',
  module: {
    loaders: [
        loader: 'babel',
        test: /\.jsx$/,
        query: {
          presets: ['es2015', 'react']
  externals: [
    (function () {
      var IGNORES = [
      return function (context, request, callback) {
        if (IGNORES.indexOf(request) >= 0) {
          return callback(null, "require('" + request + "')");
        return callback();


Your package.json has 'electron-prebuilt' but you require 'electron' in your code. Have you tried require-ing 'electron-prebuild'?


Also, webpack.config.js:

const nodeExternals = require('webpack-node-externals')

module.exports = {
    externals: [ nodeExternals(), 'react', 'electron' ],


I tried most of the above examples, but none of them seemed to work for me. I then installed Electron using npm and then used yarn build It worked and I got my production build.

npm i electron


You can set target: 'electron' in your webpack config and then you don't have to exclude electron in externals.

From webpack documentation:

"electron" Compile for usage in Electron – supports require-ing Electron-specific modules.


A very simple solution :

const remote = window.require('electron').remote;

webpack will ignore this require

Related Query

More Query from same tag