ElectronJS-无法读取未定义的属性“ on”

时间:2019-08-04 02:44:11

标签: node.js electron

电子输出错误-无法读取未定义的属性“ 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"
  }
}

1 个答案:

答案 0 :(得分:1)

请仔细阅读电子文档https://electronjs.org/docs/tutorial/first-app。它必须是app而不是App