2017-07-02 63 views
0

我不确定哪些平台/工具是我的问题的根源,因此在SO上提出这个问题而不是Git-Hub存储库之一的问题。我试图根据Polyonic开发一个项目。 Polyonic本身就是Electron和Ionic2的种子混搭。我的项目也使用node-serialport,这是一个本地模块。使用Ionic2,串口和电子构建器构建电子系统

我的开发版本是: - 节点7.4.0 - 电子1.6.10

...在我的项目的src文件夹中运行ionic info给出:

global packages: 

    @ionic/cli-utils : 1.4.0 
    Cordova CLI  : 7.0.1 
    Gulp CLI   : CLI version 3.9.1 Local version 3.9.1 
    Ionic CLI  : 3.4.0 

local packages: 

    @ionic/app-scripts    : 1.3.7 
    @ionic/cli-plugin-cordova  : 1.4.0 
    @ionic/cli-plugin-gulp   : 1.0.1 
    @ionic/cli-plugin-ionic-angular : 1.3.1 
    Cordova Platforms    : browser 4.1.0 
    Ionic Framework     : ionic-angular 3.3.0 

System: 

    Node  : v7.4.0 
    OS   : Linux 4.6 
    Xcode  : not installed 
    ios-deploy : not installed 
    ios-sim : not installed 
    npm  : 4.0.5 

如果我这样做npm install在src目录中,然后npm install在根目录中,npm start位于根目录(在Polyonic种子中运行捆绑Ionic项目的gulp脚本),项目启动并运行完美,没有node-serialport问题。

如果我再在我的项目的根目录运行electron builder建立一个可执行文件,然后运行可执行文件,在Chrome DevTools控制台,我得到这样的输出:

Uncaught Error: The module '/home/vic/git/MyProject/build/node_modules/serialport/build/Release/serialport.node' 
was compiled against a different Node.js version using 
NODE_MODULE_VERSION 51. This version of Node.js requires 
NODE_MODULE_VERSION 53. Please try re-compiling or re-installing 
the module (for instance, using `npm rebuild` or`npm install`). 
    at process.module.(anonymous function) [as dlopen] (ELECTRON_ASAR.js:173:20) 
    at Object.Module._extensions..node (module.js:598:18) 
    at Object.module.(anonymous function) [as .node] (ELECTRON_ASAR.js:173:20) 
    at Module.load (module.js:488:32) 
    at tryModuleLoad (module.js:447:12) 
    at Function.Module._load (module.js:439:3) 
    at Module.require (module.js:498:17) 
    at require (internal/module.js:20:19) 
    at bindings (/home/vic/git/MyProject/build/node_modules/bindings/bindings.js:76:44) 
    at Object.<anonymous> (/home/vic/git/MyProject/build/node_modules/serialport/lib/bindings.js:3:35) 

我认识到,有other related questions在SO上,建议使用electron-rebuild来确保本地模块是针对Electron预期的节点版本构建的。但是,如果我去到项目src文件夹,然后运行:

rm -rf node_modules/serialport/build/* 
node_modules/.bin/electron-rebuild -w serialport -f 

...然后返回到我的项目的根文件夹,运行npm start(它通常像之前一样运行),然后运行electron-builder并运行可执行文件,在Chrome DevTools控制台,我得到这样的输出:

Uncaught Error: Cannot find module 'serialport' 
    at Module._resolveFilename (module.js:470) 
    at Function.Module._resolveFilename (/tmp/.mount_7laJTZ/usr/bin/resources/electron.asar/common/reset-search-paths.js:35) 
    at Function.Module._load (module.js:418) 
    at Module.require (module.js:498) 
    at require (internal/module.js:20) 
    at Object.<anonymous> (main.js:73788) 
    at __webpack_require__ (main.js:20) 
    at Object.<anonymous> (main.js:72414) 
    at __webpack_require__ (main.js:20) 
    at Object.<anonymous> (main.js:111408) 

这从工作比我做的事情electron-rebuild之前更远的感觉。我哪里错了?任何帮助或建议,将不胜感激。

回答

2

如果您将在下个小时发送给我项目,我会调查什么是错的。您不需要自动使用电子重建 - 电子构建器重建。 (我是电子建设者维护者。)

+0

Whoa酷,我刚刚添加你作为(私人)github回购协作者...看看在串行服务分支...你可以聊天我freenode处理vicatcu如果你想 – vicatcu

+0

你可能已经知道这一点,但仔细阅读本地和电子节点的串行端口回购问题揭示了用户空间中的许多混乱。我已经能够成功地建立了琐碎的项目:https://github.com/johnny-five-io/electron-serialport – vicatcu

+0

利用农闲直接的信息请与我联系(https://slackin.electron.build/)。不清楚如何使用freenode :) – develar

2

在使用@develar离线处理它之后,我们能够解决问题。我在这里回复并接受他的回答,在信贷到期时给予贷款。

This PR到Polyonic项目是一个直接的结果。据我估计,关键的变化,然而,改变根的package.json的构建块:

"build": { 
    "appId": "YOUR.APPID.GOES.HERE", 
    "directories": { 
    "app": "build" 
    } 
}, 

...并确保电子是在devDependencies部分,而不是依赖关系部分。

这里的关键点是Polyonic,当您运行npm start捆绑的一切行动,并把它变成一个build文件夹在你的项目的根。然后运行cd build && electron .运行启动项目。根据电子文档生成器:

  • 目录

    • buildResources =建立String - 要建立资源的路径。
    • output = dist字符串 - 输出目录。
    • 应用字符串 - 应用程序目录(包含应用程序的package.json),默认为应用程序, WWW或工作目录。

...所以设置build.directories.app到“构建”告诉电子制造商打包生成目录,这是我需要的。

相关问题