Electron build does not work without nodeIntegration
See original GitHub issueI’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:
- Created 5 years ago
- Reactions:4
- Comments:8
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
You could set nodeIntegration to true, like shown here
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 likerequire
andmodule
will not be defined. In this case, it sounds like:nodeIntegration
, somodule
andrequire
are no longer avialableIf you change the webpack target to
electron-renderer
, it should fix that.