【问题标题】:Unable to find electron app找不到电子应用程序
【发布时间】:2018-07-13 13:56:27
【问题描述】:

我在 Ubuntu 17.10 上运行 youtube tutorial,当我运行构建命令 ng build --prod && electron . 时,结果是:

启动应用程序时出错 无法在 /home/ole/angular-electron 找到 Electron 应用程序

找不到模块'/home/ole/angular-electron'

应用程序编译良好,只是 electron . 步骤失败。包含main 属性的package.json 内容如下所示:

  "name": "angular-electron",
  "version": "0.0.0",
  "license": "MIT",
  "main": "main.js",

我还尝试运行第一个答案中指示的命令,结果如下:

    ole@mki:~/angular-electron$ ng build --prod && npm run electron
    Date: 2018-02-03T02:57:31.154Z
    Hash: a2a64f9c18abdabf8e6e
    Time: 25113ms
    chunk {0} polyfills.f20484b2fa4642e0dca8.bundle.js (polyfills) 59.4 kB [initial] [rendered]
    chunk {1} main.34c2037568943aee5abc.bundle.js (main) 152 kB [initial] [rendered]
    chunk {2} styles.9c0ad738f18adc3d19ed.bundle.css (styles) 79 bytes [initial] [rendered]
    chunk {3} inline.ef66fc99c35b976a47ae.bundle.js (inline) 1.45 kB [entry] [rendered]

    > angular-electron@0.0.0 electron /home/ole/Junk/angular-electron
    > electron .

    Error launching app
    Unable to find Electron app at /home/ole/Junk/angular-electron

    Cannot find module '/home/ole/Junk/angular-electron'
    npm ERR! code ELIFECYCLE
    npm ERR! errno 1
    npm ERR! angular-electron@0.0.0 electron: `electron .`
    npm ERR! Exit status 1
    npm ERR!
    npm ERR! Failed at the angular-electron@0.0.0 electron script.
    npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

    npm ERR! A complete log of this run can be found in:
    npm ERR!     /home/ole/.npm/_logs/2018-02-03T02_57_32_025Z-debug.log
    ole@mki:~/Junk/angular-electron$ ng build --prod && npm run electron
    Date: 2018-02-03T02:59:37.741Z
    Hash: a2a64f9c18abdabf8e6e
    Time: 25083ms
    chunk {0} polyfills.f20484b2fa4642e0dca8.bundle.js (polyfills) 59.4 kB [initial] [rendered]
    chunk {1} main.34c2037568943aee5abc.bundle.js (main) 152 kB [initial] [rendered]
    chunk {2} styles.9c0ad738f18adc3d19ed.bundle.css (styles) 79 bytes [initial] [rendered]
    chunk {3} inline.ef66fc99c35b976a47ae.bundle.js (inline) 1.45 kB [entry] [rendered]

    > angular-electron@0.0.0 electron /home/ole/Junk/angular-electron
    > electron .

    Error launching app
    Unable to find Electron app at /home/ole/Junk/angular-electron

    Cannot find module '/home/ole/Junk/angular-electron'
    npm ERR! code ELIFECYCLE
    npm ERR! errno 1
    npm ERR! angular-electron@0.0.0 electron: `electron .`
    npm ERR! Exit status 1
    npm ERR!
    npm ERR! Failed at the angular-electron@0.0.0 electron script.
    npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

    npm ERR! A complete log of this run can be found in:
    npm ERR!     /home/ole/.npm/_logs/2018-02-03T02_59_38_568Z-debug.log
    ole@mki:~/Junk/angular-electron$ ng build --prod && npm run electron .
    Date: 2018-02-03T03:01:35.087Z
    Hash: a2a64f9c18abdabf8e6e
    Time: 25017ms
    chunk {0} polyfills.f20484b2fa4642e0dca8.bundle.js (polyfills) 59.4 kB [initial] [rendered]
    chunk {1} main.34c2037568943aee5abc.bundle.js (main) 152 kB [initial] [rendered]
    chunk {2} styles.9c0ad738f18adc3d19ed.bundle.css (styles) 79 bytes [initial] [rendered]
    chunk {3} inline.ef66fc99c35b976a47ae.bundle.js (inline) 1.45 kB [entry] [rendered]

    > angular-electron@0.0.0 electron /home/ole/Junk/angular-electron
    > electron . "."

    Error launching app
    Unable to find Electron app at /home/ole/Junk/angular-electron

    Cannot find module '/home/ole/Junk/angular-electron'
    npm ERR! code ELIFECYCLE
    npm ERR! errno 1
    npm ERR! angular-electron@0.0.0 electron: `electron . "."`
    npm ERR! Exit status 1
    npm ERR!
    npm ERR! Failed at the angular-electron@0.0.0 electron script.
    npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

    npm ERR! A complete log of this run can be found in:
    npm ERR!     /home/ole/.npm/_logs/2018-02-03T03_01_35_948Z-debug.log

还尝试使用electron . 单独运行电子命令。结果是一样的。它抱怨找不到electron。还尝试从node_modules 目录运行它,如下所示:

ole@mki:~/angular-electron$ ./node_modules/electron/dist/electron 。 启动应用程序时出错 在 /home/ole/angular-electron 找不到 Electron 应用程序

找不到模块'/home/ole/angular-electron'

想法?

【问题讨论】:

    标签: javascript angular electron


    【解决方案1】:

    首先像 npm i --save-dev electron 一样安装 electron 作为开发依赖项。然后像这样设置你的构建脚本:

    "electron": "electron",
    "electron-build": "ng build --prod && npm run electron"
    

    electron 没有运行的原因是它在 electron 运行脚本中包含了一个 .,例如 `"electron": "electron ."。

    编辑:

    我认为应该足够了:

    $ npm run electron
    

    您不必编辑您的package.jsonnpm 将尝试在您的node_modules/.bin 中查找electron,然后它将在您的全局依赖项中进行搜索。

    尽量避免安装全局 npm 依赖项。如果您安装命令行工具是因为您的项目需要它,那么请始终在本地安装它。

    【讨论】:

    • 我尝试了更新的命令,但仍然得到相同的结果。用我的控制台的打印输出更新了问题。想法?
    • 啊,我很抱歉。看起来electron . 是从ng build 命令调用的。我可能会在全球范围内安装electron。这应该可以解决问题。
    • 谢谢 - 希望尽快对其进行测试 - 在尝试全局安装时遇到另一个问题:stackoverflow.com/questions/48593682/…
    • 不需要安装global,npm可以在node_modules中找到electron。我认为问题就像@Michal 说的那样,所以你应该分成 2 个单独的 npm 命令:1 个用于构建,另一个用于启动应用程序
    • @Michal 我用相关问题的信息更新了答案,现在可以使用了。感谢您的所有帮助!
    【解决方案2】:

    如果您使用的是@angular/cli ~1.4.0,请确保main.jspackage.json 在同一个文件夹中。

    <root>/src
          index.html
          main.ts
    main.js
    package.json
    

    【讨论】:

    • 为我工作。按照习惯,main.js 在实际配置为从根目录加载时会放在 /src 文件夹中。
    猜你喜欢
    • 1970-01-01
    • 2016-12-07
    • 2017-05-24
    • 1970-01-01
    • 2017-02-02
    • 2016-11-30
    • 2018-03-23
    • 2020-06-28
    • 2022-06-29
    相关资源
    最近更新 更多