我已经做了几天了,我已经从Electron GitHub(https://github.com/electron/electron-quick-start)克隆了电子快速入门我得到了这个错误,但它不仅仅是这个应用程序,它是所有的应用程序。我不知道发生了什么。电子最新版本: 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.PackageJSON
{
"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"
}
}发布于 2020-04-07 06:21:39
谢谢大家的帮助,但我已经解决了这个问题:我所要做的就是在前两行后面加上分号,
const {app, BrowserWindow} = require('electron');
const path = require('path');而不是这个
const {app, BrowserWindow} = require('electron')
const path = require('path')发布于 2020-04-06 23:55:48
没有答案,- I只是在我目前正在做的一个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)
发布于 2020-04-07 00:22:36
您的电子版本低于v3.0.0。
我们可以使用3.0.0版中的whenReady()。建议您更新您的电子版本。
https://stackoverflow.com/questions/61063296
复制相似问题