question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Electron Webpack Error: Uncaught ReferenceError: require is not defined

See original GitHub issue

I have a very simple setup with electron and webpack. I’m trying to use the target electron-renderer but seems I cannot load electron in the app js file (electron-renderer process). I suspect it has something to do with the correct webpack config setup.

I keep getting this error: Uncaught ReferenceError: require is not defined

Lib versions: webpack: 1.13.1 electron-prebuilt: 1.2.0

Here is my app repository: https://github.com/Cecildt/electron-webpack

Here is my webpack.config.js details:

var path = require('path');
var webpack = require('webpack');
var CommonsChunkPlugin = webpack.optimize.CommonsChunkPlugin;

module.exports = {
  devtool: 'source-map',
  debug: true,

  entry: {
    'app': './src/index.ts'
  },

  output: {
    path: __dirname + '/build/',
    publicPath: 'build/',
    filename: '[name].js',
    sourceMapFilename: '[name].js.map',
    chunkFilename: '[id].chunk.js'    
  },

  resolve: {
    extensions: ['','.ts','.js','.json', '.css', '.html'],
    modulesDirectories: ['node_modules']
  },

  module: {
    loaders: [
      {
        test: /\.ts$/,
        loader: 'ts',
        exclude: [ /node_modules/, /releases/ ]
      },
      {
        test: /\.json$/,
        loader: 'json'
      },
      {
        test: /\.(css|html)$/,
        loader: 'raw'
      },
      {
        test: /\.(png|jpg)$/,
        loader: 'url?limit=10000'
      }
    ]
  },
  plugins: [
    new webpack.ExternalsPlugin('commonjs', ['electron'])
  ],
  externals: [

  ],
  target:'electron-renderer'
};

Hope somebody can help me! Thanks in advance.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:12
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

14reactions
danilobjrcommented, Jun 7, 2016

+1.

14reactions
subtirelumihailcommented, May 31, 2016

+1

Read more comments on GitHub >

github_iconTop Results From Across the Web

Electron Webpack `require is not defined` - Github-Gist
If you're using Webpack to bundle your Electron app and you're getting require is not defined , and you don't want to set...
Read more >
'Require is not defined' when adding electron-renderer to ...
I understand that adding the following line to my Webpack config would allow me to import electron on the renderer side. module.exports =...
Read more >
How to solve require is not defined in electronjs - YouTube
How to solve require is not defined in electron js ?Solution:I have solved this issue by updating ElectronJs VersionLet Update it to the ......
Read more >
electron 5.0.0 "Uncaught ReferenceError: require is not defined"
JavaScript : electron 5.0.0 " Uncaught ReferenceError : require is not defined " [ Gift : Animated Search Engine : https://bit.ly/AnimSearch ] ...
Read more >
webpack require is not defined | The Search Engine You Control
So just remove it to fix error. Open side panel. Webpack: Uncaught ReferenceError: require is not defined. Asked Oct 1, 2018 • 4...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found