【发布时间】:2021-08-16 05:01:51
【问题描述】:
我是electron js 的新手,我正在尝试使用devtron。当我在电子浏览器窗口中使用require 时。我面临这个错误
Uncaught ReferenceError: require is not defined
请注意,在 BrowserWindow 中使用 require 时出现此错误,而不是在代码中。我还尝试在webPreferences 中设置nodeIntegration: true, 和contextIsolation: true。我已附上截图。
这是我的 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()
})
});
【问题讨论】:
标签: javascript node.js electron