Electron + webpack "exports is not defined" with target: electron


#1

Hi, I’m new to electron and webpack and I’m trying to allow using require('electron') in my angular2 app, because I need to have access to defined globals.

I’ve found somewhere, I need to add target: 'electron' to use require('electron') in app, but when I set this property in webpack.config, app doesnt’s start and I can see an error exports is not defined (in first line of bundled js file).

Am I missing something? Is it necessary to use target: "electron" in webpack config if I want to load electron dependencies in app with require or is there any other way?


#2

Problem solved.
I had to:

  • upgrade webpack to newest version (>=1.12.4)
  • use target: 'electron-renderer' instead of target: electron

FYI:
If you look at the webpack source code, there are some differences between these two target. electron-renderer was added to webpack in this commit

now it works