我对电子和node.js还是很陌生,我正在关注如何制作购物清单应用程序的教程,但是当我尝试运行它时(使用:“ npm start”),它说:
App threw an error during load C:\Users\user\Documents\JavaScript\Electron\Shopping List\main.js:56
},
^ SyntaxError: Unexpected token }
at createScript (vm.js:80:10)
at Object.runInThisContext (vm.js:139:10)
at Module._compile (module.js:606:28)
at Object.Module._extensions..js (module.js:653:10)
at Module.load (module.js:561:32)
at tryModuleLoad (module.js:504:12)
at Function.Module._load (module.js:496:3)
at loadApplicationPackage (C:\Users\user\Documents\JavaScript\Electron\Shopping List\node_modules\electron\dist\resources\default_app.asar\main.js:287:12)
at Object.<anonymous> (C:\Users\user\Documents\JavaScript\Electron\Shopping List\node_modules\electron\dist\resources\default_app.asar\main.js:328:5)
at Object.<anonymous> (C:\Users\user\Documents\JavaScript\Electron\Shopping List\node_modules\electron\dist\resources\default_app.asar\main.js:365:3)
这是我的代码:
const electron = require("electron");
const url = require("url");
const path = require("path");
const {app , BrowserWindow , Menu} = electron;
let mainWindow;
let addWindow;
//Listen for the app to be ready
app.on("ready" , function(){
//Create new window
mainWindow = new BrowserWindow({});
//Load HTML file into the main window
mainWindow.loadURL(url.format({
pathname: path.join(__dirname , "mainWindow.html"),
protocol: "file:",
slashes:true
}));
//Build menu from template
const mainMenu = Menu.buildFromTemplate(mainMenuTemplate);
//Insert the menu
Menu.setApplicationMenu(mainMenu);
});
//Handle CreateAddWindow function
function CreateAddWindow()
{
//Create new window
addWindow = new BrowserWindow
({
width: 200,
height: 300,
title: "Add to shopping list"
});
//Load HTML file into the main window
addWindow.loadURL(url.format({
pathname: path.join(__dirname , "addWindow.html"),
protocol: "file:",
slashes:true
}));
}
const mainMenuTemplate =
[
{
label:"File",
submenu:
[
{
label:"Add Item",
CreateAddWindow()
},
{
label: "Clear Items"
},
{
label:"Quit",
accelerator: process.platform == "darwin" ? "Command+Q" : "Ctrl+Q",
click()
{
app.quit();
}
}
]
}
]
有人可以帮我吗?