3

我已经能够使用串行端口运行 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

当我用电子运行应用程序时,弹出窗口抱怨说

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 来运行。

4

1 回答 1

3
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-x64node-v46-darwin-x64

于 2015-11-19T14:46:21.827 回答