Приложение Electron не запускается, когда уже не существует - PullRequest
0 голосов
/ 06 апреля 2020

Я занимался этим уже несколько дней, я клонировал быстрый запуск электрона с 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.

пакет 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"
  }
}

Ответы [ 3 ]

0 голосов
/ 06 апреля 2020

Ваша электронная версия ниже v3.0.0.

Мы можем использовать whenReady() с версии 3.0.0. Рекомендую обновить электронную версию.

0 голосов
/ 07 апреля 2020

Спасибо всем за помощь, но я исправил проблему: все, что мне нужно было сделать, это поставить точки с запятой после первых двух строк,

const {app, BrowserWindow} = require('electron');
const path = require('path');

Вместо этого

const {app, BrowserWindow} = require('electron')
const path = require('path')
0 голосов
/ 06 апреля 2020

Сам по себе не ответ - я только что попробовал это в Electron проекте, над которым я сейчас работаю, и он работал нормально:

app.whenReady().then((choice) => {
    console.log("hey, I'm ready", choice);   
})

Для проверки реальности я бы предложил использовать готовое событие:

app.on('ready', function () {
  console.log("hey, I'm ready too!");   
});

Хотя мне приходит в голову спросить: какую версию Electron вы используете? Если вы используете версию до 7 или 8, они еще не начали "обещание" (я забыл, какая версия начала использовать Promises)

...