2016-04-03 9 views
4

私はelectronを初めて使用し、別のチュートリアルに従おうとしています。現在、私は私のapppackage.jsonのフォーマットは電子クイックスタートアプリケーションが動作しない

{ 
    "name" : "your-app", 
    "version" : "0.1.0", 
    "main" : "main.js" 
} 

これは私のmain.js

'use strict'; 

const electron = require('electron'); 
const app = electron.app; // Module to control application life. 
const BrowserWindow = electron.BrowserWindow; // Module to create native browser window. 

// 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. 
var mainWindow = null; 

// Quit when all windows are closed. 
app.on('window-all-closed', function() { 
    // On OS X 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(); 
    } 
}); 

// This method will be called when Electron has finished 
// initialization and is ready to create browser windows. 
app.on('ready', function() { 
    // Create the browser window. 
    mainWindow = new BrowserWindow({width: 800, height: 600}); 

    // and load the index.html of the app. 
    mainWindow.loadURL('file://' + __dirname + '/index.html'); 

    // Open the DevTools. 
    mainWindow.webContents.openDevTools(); 

    // Emitted when the window is closed. 
    mainWindow.on('closed', function() { 
    // 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. 
    mainWindow = null; 
    }); 
}); 

であるこの

your-app/ 
├── package.json 
├── main.js 
└── index.html 

のように構成されているがWrite my First Electron App

にこのリンクを以下のよindex.htmlは、私が表示したいWebページである:私は私のアプリのソースディレクトリにelectronコマンドを実行すると

<!DOCTYPE html> 
<html> 
    <head> 
    <meta charset="UTF-8"> 
    <title>Hello World!</title> 
    </head> 
    <body> 
    <h1>Hello World!</h1> 
    We are using node <script>document.write(process.versions.node)</script>, 
    Chrome <script>document.write(process.versions.chrome)</script>, 
    and Electron <script>document.write(process.versions.electron)</script>. 
    </body> 
</html> 

は今、それがこの

this

の代わりに、この結果

insteadを示し

空き領域にindex.htmlをドラッグするたびに第1の画像の第2の画像のような結果を得る。

私は何が間違っているのか分かりません。この簡単なアプリケーションでどこが間違っているのか教えてください。どんな種類の助けにも感謝します。

+0

どのパラメータを電子に渡していますか? – dandavis

+0

私はちょうど「電子」と書いてください –

+0

あなたはファイル名を渡す必要があります、表示された画像のヘルプに従ってください。 – dandavis

答えて

4

を記述する必要があります。

+1

これは私のためにもUbuntuで働いた16.04 –

+0

それはあなたのために働いたと聞いてうれしい。 –

+1

これはウェブのどこにも記載されていません。私は少なくとも半日を無駄にして非常にイライラしていた。あなたは残りの時間を保存しました。ありがとう! – Abhi

2

「電子」コマンドを実行しているときに、任意のパラメータを提供しない場合には、(電子がデフォルトで実行される)index.jsにmain.jsの名前を変更

+1

同じ結果 –

+1

ファイル名を変更しても問題は解決しませんでした。パラメタとして.htmlファイルを渡して解決しました。 –

5

あなたがpackage.jsonが引数として存在するディレクトリを渡す必要があります電子命令に変換する。アプリのディレクトリ内から電子を実行している場合 は、だから、私はこの問題を解決するためにelectron index.htmlを実行する必要が

electron . 
+1

いいえ..私のアプリの中から...私はそれを実行する電子index.htmlを実行する必要があります –

関連する問題