node.js - 在Linux/macOS上安装Electronic时出现问题

标签 node.js npm electron

我需要使用Angular和Electron创建一个应用程序。这个应用程式应该可以在Windows/macOs和Linux上运作。

我试图在Windows上运行它,但它正常工作。但是当我尝试使用macOS或Linux时,它会失败...

这是我使用npm run electron运行时的输出:

Error: Electron failed to install correctly, please delete node_modules/electron and try installing again
    at Object.<anonymous> (/usr/lib/node_modules/electron/index.js:9:9)
    at Module._compile (internal/modules/cjs/loader.js:688:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
    at Module.load (internal/modules/cjs/loader.js:598:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
    at Function.Module._load (internal/modules/cjs/loader.js:529:3)
    at Module.require (internal/modules/cjs/loader.js:636:17)
    at require (internal/modules/cjs/helpers.js:20:18)
    at Object.<anonymous> (/usr/lib/node_modules/electron/cli.js:3:16)
    at Module._compile (internal/modules/cjs/loader.js:688:30)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! open-terminal@0.0.0 electron: `ng build --base-href ./ && electron .`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the open-terminal@0.0.0 electron script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

在我的package.json中,我创建了"electron": "ng build --base-href ./ && electron ."来运行我的应用。

我试图删除并重新安装,但是失败了。
我尝试重新安装:sudo npm install electron --verbose
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! electron@3.0.10 postinstall: `node install.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the electron@3.0.10 postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

最佳答案

在linux,macOS和Windows上 Electron 版的构建说明不同。按照 Electron 文档为Linux构建,请按照以下步骤操作:

1. 确保系统上安装了python2.7.x。您可以通过运行python -V命令来检查在您的操作系统上运行的python版本。

2. 安装nodejs。您可以从here.下载安装程序

3. 由于您没有提到您正在运行的linux版本,因此我假设您正在运行Ubuntu。安装以下软件包。

sudo apt-get install build-essential clang libdbus-1-dev libgtk-3-dev \
                   libnotify-dev libgnome-keyring-dev libgconf2-dev \
                   libasound2-dev libcap-dev libcups2-dev libxtst-dev \
                   libxss1 libnss3-dev gcc-multilib g++-multilib curl \
                   gperf bison python-dbusmock 

这些是在Linux上构建 Electron 版所需的非常基本的步骤。您可能需要安装其他几个软件包,具体取决于您的系统架构,项目依赖项等。

有关完整的构建说明,请遵循 Electron 文档。在这里,我为您提供了一些链接。

1. Build Instructions for linux

2. Build Instructions for macOS

3. Build Instructions for windows

关于node.js - 在Linux/macOS上安装Electronic时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53393675/

相关文章:

javascript - Amazon S3 给出 InvalidDigest : The Content-MD5 you specified was invalid

node.js - 我部署了我的项目,我收到此错误输入文件包含不受支持的图像格式

javascript - Webpack 输出为空对象

electron - Electron 和 Angular JS 之间的交互

electron - 运行构建版本时 Electron 失败

node.js - req.session 在路由中未定义

javascript - 使用 Node JS 在 Node JS 上进行 HTTP 请求回调

node.js - 链接的模块显示为未满足的依赖关系

javascript - 在 Ubuntu Zesty 17.04 上安装 Node 6.9

javascript - 在Electron App中,app.quit()&&.exit(0)无法终止进程,如何处理?