require() not defined in Electron HTML page(在 Electron HTML 页面中未定义 require())
问题描述
我目前无法在 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()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 Electron HTML 页面中未定义 require()


基础教程推荐
- npm start 错误与 create-react-app 2022-01-01
- 检查 HTML5 拖放文件类型 2022-01-01
- Bokeh Div文本对齐 2022-01-01
- 如何添加到目前为止的天数? 2022-01-01
- Fabric JS绘制具有活动形状的多边形 2022-01-01
- 原生拖动事件后如何获取 mouseup 事件? 2022-01-01
- fetch 是否支持原生多文件上传? 2022-01-01
- Bootstrap 模态出现在背景下 2022-01-01
- 即使用户允许,Gmail 也会隐藏外部电子邮件图片 2022-01-01
- 在 contenteditable 中精确拖放 2022-01-01