javascript - 电子应用程序不会启动,准备就绪时不存在
问题描述
我已经做了几天了,我已经从 Electron GitHub 克隆了电子快速启动(https://github.com/electron/electron-quick-start)我收到了这个错误,但它不是t 只为这个应用程序,它是所有的应用程序。我不知道发生了什么。电子最新版本:8.2.0 错误
app.whenReady().then(createWindow)
^
TypeError: Cannot read property 'whenReady' of undefined
at Object.<anonymous> (/Users/user/Downloads/electron-quick-start-master/main.js:25:5)
at Module._compile (internal/modules/cjs/loader.js:1147:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1167:10)
at Module.load (internal/modules/cjs/loader.js:996:32)
at Function.Module._load (internal/modules/cjs/loader.js:896:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
at internal/main/run_main_module.js:17:47
代码:
const electron = require('electron')
// Modules to control application life and create native browser window
const {app, BrowserWindow} = require('electron')
const path = require('path')
function createWindow () {
// Create the browser window.
const mainWindow = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
preload: path.join(__dirname, 'preload.js')
}
})
// and load the index.html of the app.
mainWindow.loadFile('index.html')
// Open the DevTools.
// mainWindow.webContents.openDevTools()
}
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.whenReady().then(createWindow)
// Quit when all windows are closed.
app.on('window-all-closed', function () {
// On macOS it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
if (process.platform !== 'darwin') app.quit()
})
app.on('activate', function () {
// On macOS it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (BrowserWindow.getAllWindows().length === 0) createWindow()
})
// In this file you can include the rest of your app's specific main process
// code. You can also put them in separate files and require them here.
包JSON
{
"name": "electron-quick-start",
"version": "1.0.0",
"description": "A minimal Electron application",
"main": "main.js",
"scripts": {
"start": "electron ."
},
"repository": "https://github.com/electron/electron-quick-start",
"keywords": [
"Electron",
"quick",
"start",
"tutorial",
"demo"
],
"author": "GitHub",
"license": "CC0-1.0",
"devDependencies": {
"electron": "^8.2.0"
}
}
解决方案
本身不是一个答案——我只是在Electron
我目前正在进行的一个项目中尝试了这个,它运行良好:
app.whenReady().then((choice) => {
console.log("hey, I'm ready", choice);
})
对于现实检查,我建议使用 ready 事件:
app.on('ready', function () {
console.log("hey, I'm ready too!");
});
Electron
尽管我突然想问:您使用的是什么版本?如果您使用的是 7 或 8 之前的版本,他们还没有开始“承诺”的东西(我忘记了开始使用的版本Promises
)
推荐阅读
- python - Django 原子事务适用于 sqlite,但不适用于 postgresql
- fortran - netcdf fortran如何检索全局属性的总数
- mysql - 如何获取 MySQL 连续的时间戳差异?
- xml - 向 .asmx 服务 (VB.NET) 发送请求 (XML)
- google-sheets - GoogleSheets:ISBETWEEN 的数组参数大小不同。= 介于(11,$F3:F20,$G3:G20)
- ios - 不同的出口动作目的地属性有什么区别
- javascript - 是否可以使用 python 编写网站的后端,以便我可以调用 python 方法并显示其输出?
- python - 如何使用 N-Beats 算法和 pytorch 预测来预测 K 单变量时间序列?
- javascript - 有人可以解释一下这段代码的含义吗?
- c# - Xamarin Forms TapGestureRecognizer 未发出命令