电子输出错误-无法读取未定义的属性“ on”。
尝试在全局和局部移除电子并重新安装,但仍然会出现相同的错误
用于运行电子的端子Cmd-npm启动
Index.js
const electron = require('electron')
const url = require('url')
const path = require('path')
const { App, BrowserWindow } = electron
let mainWindow
App.on('ready', function() {
console.log('App is now ready!')
//Main Window
mainWindow = new BrowserWindow({})
mainWindow.loadURL(url.format({
pathname: path.join(__dirname, 'Index.html'),
protocol: 'file',
slashes: true
}))
})
package.json
{
"name": "1",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "electron ."
},
"author": "",
"license": "ISC",
"dependencies": {
"electron": "^6.0.0"
}
}