问题描述
我目前无法在main.js文件之外的Javascript文件中加载Electron模块。
I'm currently unable to load Electron modules in Javascript files outside of the main.js file.
我正在尝试使用:
const electron = require('electron');
const ipcRenderer = electron.ipcRenderer;
在名为settings.js的文件中。
in a file called settings.js.
我安装了正确的NPM模块(eletron-prebuilt)。
I have the correct NPM modules installed (eletron-prebuilt).
设置页面加载在webview中,如下所示:
The settings page is loaded in a webview like so:
< webview id =settingssrc =./ settings.html>< / webview>
和settings.js包含如下:
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?
非常感谢。
推荐答案
您在webview中加载它,不支持 nodeintegration 。
You're loading it in a webview, which doesn't support nodeintegration by default.
将 nodeintegration
属性添加到您的webivew。
Add the nodeintegration
attribute to your webivew.
<webview id="settings" src="./settings.html" nodeintegration></webview>
这篇关于require()未在Electron HTML页面中定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!