Javascript 电子重建“无法找到电子应用程序......”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/37489543/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
electron-rebuild "Unable to find Electron app ..."
提问by SteveB
After installing a native module via npm for use with Electron (atom shell) I'm trying to run electron-rebuild:
通过 npm 安装本机模块以与 Electron(原子外壳)一起使用后,我正在尝试运行电子重建:
>>./node_modules/.bin/electron-rebuild
from the project directory,b "~/project_js/React-Redux-Py-Electron/" (which containsnode_modules/). But I receive this error message:
从项目目录中,b“~/project_js/React-Redux-Py-Electron/”(包含node_modules/)。但我收到此错误消息:
>>Unable to find Electron app at ~/project_js/React-Redux-Py-Electron/console.log(process.versions.modules)
Using versions:
使用版本:
node v6.2.0,
npm 3.8.9,
electron-prebuilt 1.2.0,
electron-rebuild 1.1.4,
which I believe are all the latest. At one time, perhaps before some version upgrades, this worked.
我相信都是最新的。有一次,也许在某些版本升级之前,这是有效的。
Can anyone explain and suggest a fix? Thanks.
任何人都可以解释并建议修复吗?谢谢。
回答by Abraham Jagadeesh
Check if your package.json has "main" key. Here main.js is your Electron Configuration JS file.
检查您的 package.json 是否有“main”键。这里的 main.js 是你的 Electron Configuration JS 文件。
{
"name": "appname",
"version": "0.0.0",
"license": "MIT",
"main": "main.js"
}
回答by Mr. Ratnadeep
The entry point file name and package.json
main file name should be same. Consider your entry point file name is app.js
then package.json
looks like
入口点文件名和package.json
主文件名应该相同。考虑您的入口点文件名app.js
然后package.json
看起来像
{
"name": "myelectron",
"version": "1.0.0",
"description": "",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "electron ."
},
"author": "",
"license": "ISC",
"devDependencies": {
"electron": "^2.0.3"
}
}
回答by Penkey Suresh
For me it was throwing this error because of missing package.json
file in the folder I was running electron
command. Make sure the folder consists of files named
对我来说,这是因为package.json
我正在运行electron
命令的文件夹中缺少文件而引发此错误。确保该文件夹包含名为
main.js
index.html
package.json
main.js
index.html
package.json
and define variables electron
, app
and BrowserWindow
in main.js
are as
并定义变量electron
, app
并BrowserWindow
在main.js
如
const electron = require('electron');
const {app, BrowserWindow} = electron;
回答by Kiran Maniya
Make sure you defined entry point for the application. generally, it's always a index.js
or main.js
. You need to specify in package.json
as an entry point of application. In this case what happened is, electron need the entry point and it didn't find from package.json
and unable to start the main process
. To fix it up, You can add main
property as root property in package.json as given below,
确保您为应用程序定义了入口点。通常,它总是一个index.js
or main.js
。您需要将 in 指定package.json
为应用程序的入口点。在这种情况下发生的情况是,电子需要入口点,但它没有找到 frompackage.json
并且无法启动main process
. 要修复它,您可以main
在 package.json 中添加属性作为根属性,如下所示,
{
"name": "YOUR_APP_NAME",
"version": "1.0.0",
"main": "main.js"
}
Another important thing is, just check once the dependencies by running command npm list --depth=0
and confirm that electron
is there.
另一件重要的事情是,只需通过运行命令检查一次依赖项npm list --depth=0
并确认它electron
存在。
回答by pg2286
for me the issue was caused due to inconsistency with the name when running the Electron
command.
对我来说,问题是由于运行Electron
命令时名称不一致引起的。
Ensure that the filename provided for run should be the same as the one provided in the mainentry in package.json e.g. on Mac OS
/Applications/Electron.app/Contents/MacOS/Electron hello-world
matches with the hello-world.js
in mainpackage.json
确保提供给运行的文件名应该是一样的,在所提供的一个主要中的package.json例如,在Mac OS项
/Applications/Electron.app/Contents/MacOS/Electron hello-world
与匹配hello-world.js
的主要的package.json
{
"name": "first_electron_app",
"version": "0.0.1",
"main": "hello-world.js",
"dependencies": {
}
}
回答by Trey Huffine
npm run build && npm start
fixed it for me
npm run build && npm start
为我修好了