Electron and Webpack error over redefining process and __dirname

I just tried to build a new project with Electron and webpack (along with React and babel).

But I lost a couple of hours to figure out an error, thinking that I did something wrong. But it turns out that webpack didn’t follow the principle of least surprise. For some reason, webpack believes, that if you use the same variable name as node, you should be using node and mangled them, silently, no log, no warning, just deal with it!

The problem is not hard to fix. You just add to your plugin section in your config, an ignorePlugin for electron, or any other plugin you didn’t configure but is applied anyway.

plugins: [
    new webpack.IgnorePlugin(new RegExp("^(electron)$")),
]
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s