Reputation: 95
As I created my first app and run, I got this error.
TypeError [ERR_INVALID_ARG_TYPE]: The "id" argument must be of type string. Received type object
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();
}
});
What went wrong here?
Upvotes: 9
Views: 29276
Reputation: 56754
You already require
d electron, so use it:
const electron = require("electron");
const { app, BrowserWindow } = electron;
If all you need from electron
is app
and BrowserWindow
, simply destructure right from the require
:
const { app, BrowserWindow } = require("electron");
Upvotes: 1
Reputation: 4067
Your problem is here
const { app, BrowserWindow } = require(electron);
With the following fix
const { app, BrowserWindow } = require('electron');
This is because require()
requires a string as a parameter.
Upvotes: 12