我已经做了几天了,我已经从 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 windowconst {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()})
3 回答
慕尼黑5688855
TA贡献1848条经验 获得超2个赞
本身不是一个答案——我只是在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)
繁星淼淼
TA贡献1775条经验 获得超11个赞
谢谢大家帮助我,但我已经解决了这个问题:我所要做的就是在前两行之后加上分号,
const {app, BrowserWindow} = require('electron');
const path = require('path');
而不是这个
const {app, BrowserWindow} = require('electron')
const path = require('path')
添加回答
举报
0/150
提交
取消