canboat / canboatjs

Native javascript NMEA 2000 decoder and encoder
Apache License 2.0
95 stars 39 forks source link

TypeError: SerialPort is not a constructor #242

Closed gabsi55 closed 1 year ago

gabsi55 commented 1 year ago

With a recent SignalK installation via NodeJS i encountered the following error. What can I do against it? Thanks in advance.

TypeError: SerialPort is not a constructor at SerialStream.start (/usr/local/lib/node_modules/signalk-server/node_modules/@canboat/canboatjs/lib/serial.js:116:19) at new SerialStream (/usr/local/lib/node_modules/signalk-server/node_modules/@canboat/canboatjs/lib/serial.js:90:8) at Object.nmea2000input [as NMEA2000] (/usr/local/lib/node_modules/signalk-server/node_modules/@signalk/streams/simple.js:242:7) at new Simple (/usr/local/lib/node_modules/signalk-server/node_modules/@signalk/streams/simple.js:82:34) at createPipeElement (/usr/local/lib/node_modules/signalk-server/lib/pipedproviders.js:75:16) at /usr/local/lib/node_modules/signalk-server/lib/pipedproviders.js:48:30 at Array.reduce () at createPipedProvider (/usr/local/lib/node_modules/signalk-server/lib/pipedproviders.js:46:55) at /usr/local/lib/node_modules/signalk-server/lib/pipedproviders.js:82:37 at Array.reduce () at Object.startProviders [as start] (/usr/local/lib/node_modules/signalk-server/lib/pipedproviders.js:79:62) at Server. (/usr/local/lib/node_modules/signalk-server/lib/index.js:329:66) at Generator.next () at fulfilled (/usr/local/lib/node_modules/signalk-server/lib/index.js:23:58) at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

sbender9 commented 1 year ago

What version of nodejs are you running?

I think something is off with your install. Try removing the server and installing again.

https://github.com/SignalK/signalk-server/wiki/FAQ:-Frequently-Asked-Questions#somethings-wrong-i-need-to-reinstall--reset-my-system

gabsi55 commented 1 year ago

I have Node.js v18.17.1 on an ubuntu system.

I also tried a reinstall but did not solve the problem. Is this setup with nodejs running in ubuntu environments?

sbender9 commented 1 year ago

Normally should be fine on ubuntu, but not sure about serialport support for your hardware.

Can you check /usr/local/lib/node_modules/signalk-server/node_modules/serialport/package.json to see what version is installed?

Also check /usr/local/lib/node_modules/signalk-server/node_modules/@canboat/canboatjs/node_modules/serialport/package.json

gabsi55 commented 1 year ago

It is a Actisense NGT-1.. With a serial terminal a can open a connection. Serialport version: 11.0.1

The second directory is not existing. There is the dir @serialport but it is empty.

Thanks for your help.

tkurki commented 1 year ago

Scott, I think this is what has happened here (and elsewhere):

Previously server and canboatjs were using serialport@9. Npm was smart enough to detect that, depuplicated serialport and it was only installed under signalk-server/node_modules and canboatjs at signalk-server/node_modules/@canboat/canboatjs would pick it from there.

When server switched to serialport@11 npm was not smart enough when updating the server to detect that canboatjs's dependency is no longer met properly and here we are, canboatjs invoking serialport@9 api but loading serialport@11.

This is why you can't replicate the situation just by installing signalk-server. Should be easy enough to verify, but commuting right now....

I think running npm install -g signalk-server should fix things.

sbender9 commented 1 year ago

oddly enough, I get the same error with canboatjs 2.1 . But you should not have that.

Can you check the canboatjs version?

sbender9 commented 1 year ago

ok., they released a new serialport 11.0.1 a couple weeks ago. I think this might be related. trying to figure this out...

sbender9 commented 1 year ago

There should actually be a /usr/local/lib/node_modules/signalk-server/node_modules/@canboat/canboatjs/node_modules/serialport/

And it should be serialport v 9.2.8, I just did a fresh install on raspberry pi and it's there.

can you try sudo npm install -g @canboatjs/canboatjs@1.28.2

look for errors with that, if no errors, then try

actisense-serialjs /dev/path/to/your/actisense

gabsi55 commented 1 year ago

It worked with sudo npm i -g @canboat/canboatjs@1.28.2 i can install it. But actisense-serialjs fails with

Error: Cannot find module 'serialport'

gabsi55 commented 1 year ago

By installing serialport V10.0.0 i got it to work.

How can i now get this version into signalk-server? Do i have to edit the dependencies?

sbender9 commented 1 year ago

I just published canboatjs v1.28.3 that should fix this

just do sudo npm install -g signalk-server and you should get the new version

gabsi55 commented 1 year ago

Working perfect. Thanks