需要预先安装如下工具: python2.x, npm, visual studio.
npm需要安装工具node-pre-gyp和node-gyp

npm install -g npm-pre-gyp
npm install -g npm-gyp

在项目中

npm install serialport

哦, 每次装到最后都不显示任何信息了....
如果这时候require('serialport'),会出现这个错误:

C:\r\electron\macgetter\node_modules\bindings\bindings.js:91
  throw err
  ^

Error: Could not locate the bindings file. Tried:
 → C:\r\electron\macgetter\node_modules\serialport\build\serialport.node
 → C:\r\electron\macgetter\node_modules\serialport\build\Debug\serialport.node
 → C:\r\electron\macgetter\node_modules\serialport\build\Release\serialport.node
 → C:\r\electron\macgetter\node_modules\serialport\out\Debug\serialport.node
 → C:\r\electron\macgetter\node_modules\serialport\Debug\serialport.node
 → C:\r\electron\macgetter\node_modules\serialport\out\Release\serialport.node
 → C:\r\electron\macgetter\node_modules\serialport\Release\serialport.node
 → C:\r\electron\macgetter\node_modules\serialport\build\default\serialport.node
 → C:\r\electron\macgetter\node_modules\serialport\compiled\5.2.0\win32\x64\serialport.node
    at bindings (C:\r\electron\macgetter\node_modules\bindings\bindings.js:88:9)
    at Object.<anonymous> (C:\r\electron\macgetter\node_modules\serialport\lib\bindings.js:3:35)
    at Module._compile (module.js:399:26)
    at Object.Module._extensions..js (module.js:406:10)
    at Module.load (module.js:345:32)
    at Function.Module._load (module.js:302:12)
    at Module.require (module.js:355:17)
    at require (internal/module.js:13:17)
    at Object.<anonymous> (C:\r\electron\macgetter\node_modules\serialport\lib\serialport.js:12:25)
    at Module._compile (module.js:399:26)

根据网上的解决方案:进入项目目录

C:\r\electron\macgetter>cd node_modules\serialport
C:\r\electron\macgetter\node_modules\serialport>node-gyp rebuild
输出一堆信息......最后
gyp info ok

然后就可以了.

标签: none 阅读量: 1540

添加新评论