[英]Uncaught ReferenceError: require is not defined in Electron BrowserWindow
I am new to electron js
and I am trying to use devtron
.我是
electron js
的新手,我正在尝试使用devtron
。 When I use require
in the Electron Browser Window.当我在 Electron 浏览器 Window 中使用
require
时。 I face this error我面临这个错误
Uncaught ReferenceError: require is not defined
未捕获的 ReferenceError:未定义要求
Please note that I am getting this error when using require in BrowserWindow, not in the code.请注意,在 BrowserWindow 中使用 require 时出现此错误,而不是在代码中。 I have also tried setting
nodeIntegration: true,
and contextIsolation: true
in webPreferences
.我还尝试在
webPreferences
中设置nodeIntegration: true,
和contextIsolation: true
。 I have attached the screenshot.我附上了截图。
Here is my code of main.js这是我的 main.js 代码
const {app, BrowserWindow} = require('electron')
const path = require('path')
require('electron-reload')(__dirname);
function createWindow () {
const mainWindow = new BrowserWindow({
width: 1000,
height: 700,
webPreferences: {
preload: path.join(__dirname, 'preload.js'),
nodeIntegration: true,
contextIsolation: true
}
})
mainWindow.loadFile('index.html')
}
app.whenReady().then(() => {
createWindow()
app.on('activate', function () {
if (BrowserWindow.getAllWindows().length === 0) createWindow()
})
});
contextIsolation
is enabled, disable contextIsolation
and nodeIntegration
should work. contextIsolation
已启用,禁用contextIsolation
和nodeIntegration
应该可以工作。
webPreferences: {
nodeIntegration: true,
contextIsolation: false
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.