“id”参数必须是字符串类型。接收类型对象

har*_*roh 9 node.js npm electron

当我创建第一个应用程序并运行时,我收到此错误。

类型错误 [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();
  }
});
Run Code Online (Sandbox Code Playgroud)

这里出了什么问题?

mho*_*ovd 11

你的问题就在这里

const { app, BrowserWindow } = require(electron);
Run Code Online (Sandbox Code Playgroud)

通过以下修复

const { app, BrowserWindow } = require('electron');
Run Code Online (Sandbox Code Playgroud)

这是因为require()需要一个字符串作为参数。