node-serialport: TypeError: SerialPort.parsers.ReadLine is not a function

SerialPort version: 4.x NodeJS Version: 4.5 Operating System and Hardware: raspian jesse lite & pi zero Are you using Electron/Atom/NwJS?: No

(Run node -v && npm -v && python --version to get version numbers)

Summary of Problem

Reading the serial port without a parser works just fine; but, when running the example code for the readline parser I receive this error:

var parser = SerialPort.parsers.ReadLine();
                                ^
TypeError: SerialPort.parsers.ReadLine is not a function
    at Object.<anonymous> (/home/pi/rfid/serialport.js:4:33)
    at Module._compile (module.js:409:26)
    at Object.Module._extensions..js (module.js:416:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Function.Module.runMain (module.js:441:10)
    at startup (node.js:139:18)
    at node.js:974:3

Expected Behavior

That the example code for the readline parser would run:

var SerialPort = require('serialport');
var ReadLine = SerialPort.parsers.ReadLine;
var port = new SerialPort('/dev/serial0');
var parser = SerialPort.parsers.ReadLine();
port.pipe(parser);
parser.on('data', console.log);

Any idea what could be causing this error? I have installed the code using

npm install serialport

and

npm install serialport --build-from-source

I installed node two different ways with the same results… self compiled and downloading the arm6 binaries.

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 16 (8 by maintainers)

Most upvoted comments

Or upgrade your code to 5x, which is a lot faster and less buggy.

You’re looking at the docs for the latest master not for 4.x https://github.com/EmergingTechnologyAdvisors/node-serialport/blob/4.0.1/README.md