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