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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 20:23:17  来源:igfitidea点击:

electron-rebuild "Unable to find Electron app ..."

javascriptnode.jselectron

提问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.jsonmain file name should be same. Consider your entry point file name is app.jsthen package.jsonlooks 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.jsonfile in the folder I was running electroncommand. Make sure the folder consists of files named

对我来说,这是因为package.json我正在运行electron命令的文件夹中缺少文件而引发此错误。确保该文件夹包含名为

  1. main.js
  2. index.html
  3. package.json
  1. main.js
  2. index.html
  3. package.json

and define variables electron, appand BrowserWindowin main.jsare as

并定义变量electronappBrowserWindowmain.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.jsor main.js. You need to specify in package.jsonas an entry point of application. In this case what happened is, electron need the entry point and it didn't find from package.jsonand unable to start the main process. To fix it up, You can add mainproperty as root property in package.json as given below,

确保您为应用程序定义了入口点。通常,它总是一个index.jsor 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=0and confirm that electronis there.

另一件重要的事情是,只需通过运行命令检查一次依赖项npm list --depth=0并确认它electron存在。

回答by pg2286

for me the issue was caused due to inconsistency with the name when running the Electroncommand.

对我来说,问题是由于运行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-worldmatches with the hello-world.jsin 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 startfixed it for me

npm run build && npm start为我修好了