2016-10-22 5 views
0

Ich versuche, eine einfache Electron-basierte Anwendung zu erstellen, basierend auf den Anweisungen unter http://electron.atom.io/docs/tutorial/quick-start/, die den folgenden Code bereitstellen. Wenn ich laufen Sie versuchen, es mit Elektron 1.4.4 und 6.7.0 NodeJS ich:Probleme beim Ausführen einer elektronenbasierten Anwendung?

TypeError: Cannot read property 'on' of undefined 
    at Object.<anonymous> (/path/to/proj/src/goelectron.js:29:4) 

Der Code folgt:

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

// Keep a global reference of the window object, if you don't, the window will 
// be closed automatically when the JavaScript object is garbage collected. 
let win 

function createWindow() { 
    // Create the browser window. 
    win = new BrowserWindow({width: 800, height: 600}) 

    // and load the index.html of the app. 
    win.loadURL(`file://${__dirname}/index.html`) 

    // Open the DevTools. 
    win.webContents.openDevTools() 

    // Emitted when the window is closed. 
    win.on('closed',() => { 
    // Dereference the window object, usually you would store windows 
    // in an array if your app supports multi windows, this is the time 
    // when you should delete the corresponding element. 
    win = null 
    }) 
} 

// 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.on('ready', createWindow) 

// Quit when all windows are closed. 
app.on('window-all-closed',() => { 
    // 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',() => { 
    // 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 (win === null) { 
    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. 

Dies deutet darauf hin, dass ‚App‘ nicht definiert ist, aber ich bin nicht vertraut mit der Notation die bietet const {app, BrowserWindow} = require('electron'), so bin ich mir nicht sicher, wie man überprüft, was falsch ist?

Antwort

1

Stellt sich heraus, dies soll mit dem ‚Elektron‘ Befehl ausgeführt werden, so da ich es nicht global installiert haben (vorausgesetzt, die ich in meinem Projektverzeichnis bin):

node_modules/.bin/electron ./src/goelectron.js 

sonst, wenn ich es hatte, wäre:

electron ./src/goelectron.js 
+1

Sie sollten 'global nicht installieren electron', stattdessen sollten Sie eine NPM-Skript zu' package.json' hinzufügen, die 'Elektron src/goelectron.js' läuft. –

+0

Der Vorschlag, der package.json hinzuzufügen, ist nützlich - danke –

Verwandte Themen