在 Electron HTML 页面中未定义 require() [英] require() not defined in Electron HTML page

查看:20
本文介绍了在 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()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆