“ id”参数必须为字符串类型。收到的类型对象

时间:2020-04-29 11:04:56

标签: node.js npm electron

我是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();
  }
});

这里出了什么问题?

1 个答案:

答案 0 :(得分:0)

您的问题在这里

const { app, BrowserWindow } = require(electron);

使用以下修复程序

const { app, BrowserWindow } = require('electron');

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