ElectronJs:HellowWorld应用程序未启动 [英] ElectronJs: HellowWorld application is not starting

查看:114
本文介绍了ElectronJs:HellowWorld应用程序未启动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经开始使用electronic js hello world应用程序
第一次使用electronic

I have started with electron js hello world application first application with electron

我正在按照指示进行操作。

I am doing exactly what is instructed.

已创建3个文件 main.js,index.html,package.json

package.json

package.json

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

main.js

const electron = require('electron');
// Module to control application life.
const {app} = electron;
// Module to create native browser window.
const {BrowserWindow} = 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 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();
  }
});

app.on('activate', () => {
  // On OS X 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.

index.html

index.html

<!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>

然后安装了Electron Globaly

then installed Electron Globaly

npm install electron-prebuilt -g

然后尝试使用以下命令运行应用程序

then trying to run the application using

electron .

,但没有任何反应。结果是

but nothing is happening. Here is the result

C:\Users\abc\Desktop\electrons\1>electron .

C:\Users\abc\Desktop\electrons\1>

---编辑

我尝试在package.json中添加脚本来启动电子

I have tried added script in package.json to start the electron

{
...
scripts:{ start: electron main.js}
...
}

{ ... "scripts":{"start":"electron main.js"} ... }

然后当我使用<$ c $运行应用程序时c> npm start
这是结果

and then when I ran the app using npm start Here is the result

C:\Users\abc\Desktop\electrons\1>npm start

> your-app@0.1.0 start C:\Users\abc\Desktop\electrons\1
> electron main.js


npm ERR! Windows_NT 6.3.9600
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\abc\\AppData\
\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js" "start"
npm ERR! node v4.4.4
npm ERR! npm  v3.9.0
npm ERR! code ELIFECYCLE
npm ERR! your-app@0.1.0 start: `electron main.js`
npm ERR! Exit status 3221225781
npm ERR!
npm ERR! Failed at the your-app@0.1.0 start script 'electron main.js'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the your-app package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     electron main.js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs your-app
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls your-app
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     C:\Users\abc\Desktop\electrons\1\npm-debug.log

C:\Users\abc\Desktop\electrons\1>


推荐答案

如果您使用的是Electron 1.1.0,请不要没有安装VS2015,那么您可能会错过 VC ++ 2015运行时

If you're using Electron 1.1.0 and don't have VS2015 installed then you might be missing the VC++2015 runtime.

这篇关于ElectronJs:HellowWorld应用程序未启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆