TypeError: SerialPort is not a constructor

See original GitHub issue

I am getting the TypeError: SerialPort is not a constructor error when I npm start my React CRA project. This issue has appeared before, but I believe my code to be up to date and yet I still get this error.

Here is the code:

var portName = 'COM5'; 
var buffer = "";
var baud = 9600;
var SerialPort = require('serialport');
var serialPort = new SerialPort(portName, {baudRate:baud});

The documentation says:

const port = new SerialPort('/dev/tty-usbserial1', {
  baudRate: 57600
})

should open the port. I have tried to forgo the semicolons, but I still get the “not a constructor” error.

Info:

I am using this in a .js file in a react project. My serialport version is 9.2.0

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
reconbotcommented, Feb 26, 2022

So it looks like you’re using serialport v10 not v9

See the upgrade guide https://serialport.io/docs/guide-upgrade#upgrading-from-9x-to-10x

1reaction
kevinlinxccommented, Feb 26, 2022

@suhyouri I never made node-serialport work, at the time (July) I instead made an asynchronous Python script that read and published to and from the serial bus. Since then I’ve removed CRA from our project so I never needed to use this library again.

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeError: SerialPort is not a constructor #2434 - GitHub
const port = new SerialPort({path: '/dev/ttyUSB0', baudRate: 9600}); ^ TypeError: SerialPort is not a constructor at Object.
Read more >
Node: SerialPort is not a constructor - Stack Overflow
Another error was shown to me: throw new TypeError( "path" is not defined: ${settings.path} );. I created the port object like this: const ......
Read more >
Uncaught TypeError: p5.SerialPort is not a constructor (sketch
Hello! I'm trying to run a sketch that reads data from an Arduino sketch I'm running. The main p5.js code contains a line...
Read more >
mods - js - node_modules - serialport - CBA
Writes data to the given serial port. buffer. The buffer parameter accepts a Buffer object, or a type that is accepted by the...
Read more >
TypeError: "x" is not a constructor - JavaScript - MDN Web Docs
The JavaScript exception "is not a constructor" occurs when there was an attempt to use an object or a variable as a constructor,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found