问题
I'm currently unable to load Electron modules in Javascript files outside of the main.js file.
I'm trying to use:
const electron = require('electron');
const ipcRenderer = electron.ipcRenderer;
in a file called settings.js.
I have the correct NPM modules installed (eletron-prebuilt).
The settings page is loaded in a webview like so:
<webview id="settings" src="./settings.html"></webview>
and the settings.js included like:
<script type='text/javascript' src='./resources/js/settings.js'></script>
Running out of ideas here, but I wonder if it's some kind of scoping issue?
Many thanks.
回答1:
You're loading it in a webview, which doesn't support nodeintegration by default.
Add the nodeintegration
attribute to your webivew.
<webview id="settings" src="./settings.html" nodeintegration></webview>
来源:https://stackoverflow.com/questions/36859984/require-not-defined-in-electron-html-page