【问题标题】:NodeJS - why serial reader is failing?NodeJS - 为什么串行阅读器失败?
【发布时间】:2017-08-09 16:58:43
【问题描述】:

我已经使用 npm 安装了serialport,但是为什么连接失败?

$ ls /dev/tty.*
/dev/tty.Bluetooth-Incoming-Port    /dev/tty.usbserial-AI0255BX

$ cat /var/tmp/test.js
var SerialPort = require('serialport');
var port = new SerialPort('/dev/tty.usbserial-AI0255BX', {
  baudRate: 57600
});


$ node /var/tmp/test.js 
module.js:471
    throw err;
    ^

Error: Cannot find module 'serialport'
    at Function.Module._resolveFilename (module.js:469:15)
    at Function.Module._load (module.js:417:25)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/private/var/tmp/test.js:1:80)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)

【问题讨论】:

    标签: javascript node.js macos npm serial-port


    【解决方案1】:

    Nodejs 在与脚本相同的文件夹中搜索 package.json。如果没有找到它在父文件夹等中搜索......

    我在你的 pastbin 中看到你已经在家里安装了 node 模块,所以 package.json 对于 Node 来说是无法实现的。

    你可以试试这个:

    • npm install -g 串口

    -g(全局)选项允许无论您身在何处都可以使用该 bin。

    或者:

    • 将脚本移动到 package.json 所在的同一文件夹(或子文件夹)中

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-07-25
      • 1970-01-01
      • 1970-01-01
      • 2020-12-21
      • 1970-01-01
      • 2020-06-30
      • 1970-01-01
      • 2014-01-20
      相关资源
      最近更新 更多