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 build does not work without nodeIntegration

See original GitHub issue

I’m trying to disable nodeIntegration from the renderer process for security purposes.

Describe the issue / bug.

Electron build stops working when nodeIntegration is set to false for the mainWindow (white screen)

How can I reproduce this problem?
$ vue init simulatedgreg/electron-vue my-project

Disable everything optional except axios Delete LandingPage/SystemInformation, remove from LandingPage.vue too Remove require('electron') line from LandingPage.vue Test that web build works ($ npm run build:web) Change mainWindow creation to this:

  mainWindow = new BrowserWindow({
    height: 563,
    width: 1000,
    webPreferences: {
      nodeIntegration: false
    }
  })
  mainWindow.openDevTools();
$ npm run build

Run the program, and you’ll get white screen with error

Uncaught ReferenceError: module is not defined

If you remove libraryTarget: 'commonjs2' line from webpack.renderer.js you get the error

Uncaught ReferenceError: axios is not defined

Now if you remove axios, everything will work, but I need axios.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:4
  • Comments:8

github_iconTop GitHub Comments

17reactions
Sanjit1commented, Aug 17, 2019

You could set nodeIntegration to true, like shown here

6reactions
cloverichcommented, Mar 27, 2019

I’ve run into this issue on other projects so just throwing a guess out since there’s no response. Webpack builds have a “target” (different from libraryTarget) that tell it how to bundle and what to polyfill. E.g. if the target is node (or electron-main), its in a node environment. If its in a browser (e.g. electron-renderer), things like require and module will not be defined. In this case, it sounds like:

  • You remove nodeIntegration, so module and require are no longer avialable
  • The webpack build is still targeting a node environment

If you change the webpack target to electron-renderer, it should fix that.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Electron - require is not defined, despite nodeIntegration ...
js file, I get an error, require is not defined. I've read posts about other people having similar problem, but in their case...
Read more >
Guide | Vue CLI Plugin Electron Builder - GitHub Pages
Easily Build Your Vue.js App For Desktop With Electron. ... Native modules are supported and should work without any configuration, assuming nodeIntegration ...
Read more >
Quick Start | Electron
This guide will step you through the process of creating a barebones Hello World app in Electron, similar to electron/electron-quick-start.
Read more >
Common Configuration - electron-builder
If buildVersion is not defined and buildNumber (or one of the buildNumber envs) is defined, it will be used as a build version...
Read more >
Electron Platform Guide - Apache Cordova
cordova platform add cordova-electron cordova run cordova-electron. Preview a Project. It is not necessary to build the Electron application for previewing.
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