我是Electron js的初学者。创建第一个应用程序并运行时,出现此错误。
TypeError [ERR_INVALID_ARG_TYPE]:“ id”参数必须为字符串类型。收到类型对象
下面是编写的代码。
const electron = require("electron");
const { app, BrowserWindow } = require(electron);
let createWindow = () => {
let window = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
nodeIntegration: true,
},
});
// load the index.html file
window.loadFile("index.html");
window.webContents.openDevTools();
};
app.whenReady().then(createWindow);
// Quit when all windows closed
app.on("window-all-closed", () => {
if (process.platform !== "darwin") {
app.quit();
}
});
app.on("active", () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
}
});
这里出了什么问题?
答案 0 :(得分:0)
您的问题在这里
const { app, BrowserWindow } = require(electron);
使用以下修复程序
const { app, BrowserWindow } = require('electron');
这是因为require()
需要使用字符串作为参数。