开发者问题收集

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

2019-08-04
1019

Electron 输出错误 - 无法读取未定义的属性“on”。

尝试全局和本地删除 electron 并重新安装,但仍然出现相同的错误

用于运行 electron 的终端命令 - npm start

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个回答

请仔细阅读 electron 的文档 https://electronjs.org/docs/tutorial/first-app ,必须是 app ,而不是 App

Tien Duong
2019-08-04