lsongdev / node-escpos

🖨️ ESC/POS Printer driver for Node.js
https://npmjs.org/escpos
Other
1.38k stars 423 forks source link

SerialPort new version #383

Closed GuilhermeCouto closed 2 years ago

GuilhermeCouto commented 2 years ago

Hi everybody, I found a problem with printing on Serial ports.

Serialprinter updates and so or file adapter escpos-serialprinter must be updated too.

The error you got is TypeError: SerialPort is not a constructor

Thats because the constructor changed.

I fixed it by changing the line 16 and 17 to

const { SerialPort } = require('serialport');
this.device = new SerialPort({ path: port, baudRate: 9600, autoOpen: false });

If you could change the npm repo I will appreciate.

marceloch2 commented 2 years ago

Same here. The new version of SerialPort too.

ma-zal commented 2 years ago

Root cause

Library escpos has package.json dependencies defined without versions:

{
  "optionalDependencies": {
    "serialport": "*",
  }
}

And escpos is designed for serialport version 9. And on 11 Dec 2021 there has been released serialport version 10, which has some breaking changes.

Possible workaround

Force serialport library version 9.

1) Add to package.json:

```json
{
  ... rest of file,
  "resolutions": {
    "escpos/serialport": "9.2.8"
  }
}
```

2) Delete node_modules and yarn.lock.

3) Install all dependencies again by yarn.