我目前无法在 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="settings" src="./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?
非常感谢.
你在一个不支持 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>
这篇关于在 Electron HTML 页面中未定义 require()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
在 Electron 渲染器进程中创建子窗口时如何修复How to fix BrowserWindow is not a constructor error when creating child window in Electron renderer process(在 Electron 渲染器进程中创建子窗口
mainWindow.loadURL("https://localhost:3000/") 在 EmainWindow.loadURL(quot;https://localhost:3000/quot;) show white screen on Electron app(mainWindow.loadURL(https://localhost:3000/) 在 Electron 应用程
Electron webContents executeJavaScript:无法在第二个 loaElectron webContents executeJavaScript : Cannot execute script on second on loadURL(Electron webContents executeJavaScript:无法在第二个 loadURL 上
如何在angular-cli的组件内使用电子浏览器窗口?how to use electron browser window inside components in angular-cli?(如何在angular-cli的组件内使用电子浏览器窗口?)
ElectronJS - 在 Windows 之间共享 redux 存储?ElectronJS - sharing redux store between windows?(ElectronJS - 在 Windows 之间共享 redux 存储?)
如何在电子应用程序中访问相机/网络摄像头?How to access camera/webcamera inside electron app?(如何在电子应用程序中访问相机/网络摄像头?)