ElectronJs:HellowWorld 应用程序未启动
ElectronJs: HellowWorld application is not starting
我已经开始使用 electron js hello world 应用程序
first application with electron
我完全按照指示去做。
创建了 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 Globaly
npm install electron-prebuilt -g
然后尝试 运行 使用
的应用程序
electron .
但什么也没有发生。这是结果
C:\Users\abc\Desktop\electrons>electron .
C:\Users\abc\Desktop\electrons>
--- 编辑
我已经尝试在 package.json 中添加脚本来启动 electron
{
...
"scripts":{"start":"electron main.js"}
...
}
然后当我 运行 应用程序使用 npm start
这是结果
C:\Users\abc\Desktop\electrons>npm start
> your-app@0.1.0 start C:\Users\abc\Desktop\electrons
> 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\npm-debug.log
C:\Users\abc\Desktop\electrons>
该代码适用于我,因此它一定适合您的环境。尝试删除项目的 node_modules 文件夹 (rm -rf node_modules
),然后是 npm i
,然后是 npm start
(我假设您的 [=15= 中仍有开始任务) ]).
如果您使用的是 Electron 1.1.0 并且没有安装 VS2015,那么您可能缺少 VC++2015 runtime.
我已经开始使用 electron js hello world 应用程序 first application with electron
我完全按照指示去做。
创建了 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 Globaly
npm install electron-prebuilt -g
然后尝试 运行 使用
的应用程序electron .
但什么也没有发生。这是结果
C:\Users\abc\Desktop\electrons>electron .
C:\Users\abc\Desktop\electrons>
--- 编辑
我已经尝试在 package.json 中添加脚本来启动 electron
{ ... "scripts":{"start":"electron main.js"} ... }
然后当我 运行 应用程序使用 npm start
这是结果
C:\Users\abc\Desktop\electrons>npm start
> your-app@0.1.0 start C:\Users\abc\Desktop\electrons
> 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\npm-debug.log
C:\Users\abc\Desktop\electrons>
该代码适用于我,因此它一定适合您的环境。尝试删除项目的 node_modules 文件夹 (rm -rf node_modules
),然后是 npm i
,然后是 npm start
(我假设您的 [=15= 中仍有开始任务) ]).
如果您使用的是 Electron 1.1.0 并且没有安装 VS2015,那么您可能缺少 VC++2015 runtime.