【问题标题】:require() not defined in Electron HTML page在 Electron HTML 页面中没有定义 require()
【发布时间】:2016-08-19 23:45:26
【问题描述】:

我目前无法在 main.js 文件之外的 Javascript 文件中加载 Electron 模块。

我正在尝试使用:

const electron = require('electron');

const ipcRenderer = electron.ipcRenderer;

在名为 settings.js 的文件中。

我安装了正确的 NPM 模块(eletron-prebuilt)。

设置页面在 webview 中加载,如下所示:

<webview id="settings" src="./settings.html"></webview>

其中包括的 settings.js 如下:

<script type='text/javascript' src='./resources/js/settings.js'></script>

这里的想法用完了,但我想知道这是否是某种范围界定问题?

非常感谢。

【问题讨论】:

    标签: javascript node.js webview electron


    【解决方案1】:

    您在 webview 中加载它,默认情况下不支持 nodeintegration

    nodeintegration 属性添加到您的 webivew。

    <webview id="settings" src="./settings.html" nodeintegration></webview>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-03-23
      • 2017-10-17
      • 2021-01-16
      • 1970-01-01
      • 1970-01-01
      • 2021-03-13
      • 1970-01-01
      • 2017-05-18
      相关资源
      最近更新 更多