慕碼人8056858
2022-06-16 15:26:16
我已經做了幾天了,我已經從 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
提交
取消