Node.js ElectronJs:HelloWorld应用程序未启动

Node.js ElectronJs:HelloWorld应用程序未启动,node.js,npm,chromium,electron,Node.js,Npm,Chromium,Electron,我从electron js hello world应用程序开始 我完全按照指示去做 创建了3个文件main.js、index.html、package.json package.json { "name" : "your-app", "version" : "0.1.0", "main" : "main.js" } main.js const electron = require('electron'); // Module to control ap

我从electron js hello world应用程序开始

我完全按照指示去做

创建了3个文件
main.js、index.html、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

<!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 .
但什么都没有发生。结果如下

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

C:\Users\abc\Desktop\electrons\1>
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>
——编辑

我已经尝试在package.json中添加脚本来启动electron

{ ... “脚本”:{“开始”:“electron main.js”} ... }

然后当我使用
npm start
结果如下

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

C:\Users\abc\Desktop\electrons\1>
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>

该代码对我有效,因此它一定是您环境中的某种东西。尝试删除项目的node_modules文件夹(
rm-rf node_modules
),然后
npm i
,然后
npm start
(我假设您的包中仍然有start任务。json).

如果您使用的是Electron 1.1.0,并且没有安装VS2015,那么您可能会错过。

当我打包应用程序并在其他系统上发布时,它没有运行并提示缺少dll
msvcp140.dll和vcruntime140.dll
@VikasBansal您也需要在其他系统上安装VC++2015运行时,或者将丢失的DLL与应用程序打包(它们需要复制到与应用程序可执行文件相同的目录)。在下一次电子释放中不需要这些,因为它已经在
主分支中固定。