简体   繁体   English

未捕获的引用错误:Electron BrowserWindow 中未定义要求

[英]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已启用,禁用contextIsolationnodeIntegration应该可以工作。

webPreferences: {
  nodeIntegration: true,
  contextIsolation: false
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM