电子require()未定义 [英] Electron require() is not defined
问题描述
我正在为自己的目的创建一个Electron应用程序.我的问题是,当我在HTML页面中使用节点函数时,会引发以下错误:
I'm creating an Electron app for my own purpose. My problem is when I'm using node functions inside my HTML page it throws an error of:
'require()'未定义.
'require()' is not defined.
有什么方法可以在我所有的HTML页面中使用Node功能吗?如果可以的话,请给我举个例子,或者提供一个链接.这是我要在HTML页面中尝试使用的变量:
Is there any way to use Node functionalities in all my HTML pages? If it is possible please give me an example of how to do this or provide a link. Here are the variables I'm trying to use in my HTML page:
var app = require('electron').remote;
var dialog = app.dialog;
var fs = require('fs');
这些是我在Electron的所有HTML窗口中使用的值.
and these are the values I'm using in all my HTML windows within Electron.
推荐答案
从版本5开始,nodeIntegration
的默认值从true更改为false.
您可以在创建浏览器窗口时启用它:
As of version 5, the default for nodeIntegration
changed from true to false.
You can enable it when creating the Browser Window:
app.on('ready', () => {
mainWindow = new BrowserWindow({
webPreferences: {
nodeIntegration: true
}
});
});
这篇关于电子require()未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!