![](/img/trans.png)
[英]Electron - require is not defined, despite nodeIntegration being true
[英]Error after updating electron and changin nodeIntegration to true
我最近回到了一个旧项目并更新了我的电子版本。 我在网上发现电子现在要求您添加nodeIntegration: true
以便能够在渲染过程中导入电子。 我添加了这个,如下所示,但是,这样做后我收到以下错误并且不确定如何解决这个问题。
// Module Imports
const {app,BrowserWindow,dialog,ipcMain,remote} = require('electron')
var handlers = require('./routelist.js');
var dns = require('dns').promises;
var path = require('path');
var Connection = require('tedious').Connection;
var sql = require('sequelize');
var axios = require('axios');
let win
function createWindow () {
win = new BrowserWindow({webPreferences: {nodeIntegration: true}, width: 1730, height: 900, frame: false})
win.loadFile('./render/index.html')
win.webContents.openDevTools()
win.on('closed', () => {
win = null
})
}
app.on('ready', function() {
createWindow()
});
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit()
}
})
app.on('activate', () => {
if (win === null) {
createWindow()
}
})
错误:
Uncaught (in promise) TypeError [ERR_INVALID_ARG_TYPE]: The "id" argument must be of type string. Received type object
at validateString (internal/validators.js:112)
at Module.require (internal/modules/cjs/loader.js:768)
at require (internal/modules/cjs/helpers.js:68)
at vendor-bundle.js:7033
at new Promise (<anonymous>)
at createLoader (vendor-bundle.js:7032)
如果我能提供更多信息,请告诉我。
电子现在要求您添加 nodeIntegration: true 以便能够在渲染过程中导入电子
您不能在渲染器进程中直接使用electron
,请使用electron.remote
:
const { remote } = require('electron');
const window = new remote.BrowserWindow({ width: 800, height: 600 });
在使用 chrome 调试器很长时间试图定位发生此错误的时间后,它与电子无关。 我正在使用的供应商捆绑包为其依赖项之一传入了错误的值
感谢大家的时间。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.