使用串行端口构建电子应用程序的问题

Issues with building an electron app with serialport

我已经能够 运行 使用串行端口的 node.js 应用程序。现在尝试将其移植到电子以供跨平台使用。 'npm install serialport' 产生了以下结果:

  serialport@2.0.5 install /Users/ylh/0/electron/electron-quick-start-master/node_modules/serialport
  node-pre-gyp install --fallback-to-build

  CXX(target) Release/obj.target/serialport/src/serialport.o
  CXX(target) Release/obj.target/serialport/src/serialport_unix.o
  CXX(target) Release/obj.target/serialport/src/serialport_poller.o
  SOLINK_MODULE(target) Release/serialport.node
  COPY /Users/ylh/0/electron/electron-quick-start-master/node_modules/serialport/build/Release/node-v47-darwin-x64/serialport.node
  TOUCH Release/obj.target/action_after_build.stamp

  electron-prebuilt@0.34.3 postinstall /Users/ylh/0/electron/electron-quick-start-master/node_modules/electron-prebuilt
  node install.js

当我 运行 使用 electron 的应用程序时,弹出窗口 window 抱怨

The app provided is not a valid electron app, please read the docs on how to write one:
https://github.com/atom/electron/tree/master/docs

Error: Cannot find module '/Users/ylh/0/electron/electron-quick-start-master/node_modules/serialport/build/Release/node-v46-darwin-x64/serialport.node'

果然node_modules目录下的版本是node-v47-darwin-x64。我不知道为什么 npm install 构建 v47 但寻找 v46 到 运行.

export npm_config_disturl=https://atom.io/download/atom-shell
export npm_config_target=0.34.3
export npm_config_arch=x64
export npm_config_runtime=electron
HOME=~/.electron-gyp npm install serialport

之后,前往/Users/ylh/0/electron/electron-quick-start-master/node_modules/serialport/build/Release/

并将 electron-0.34-darwin-x64 重命名为 node-v46-darwin-x64