Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Wrong function on network adapter close?

Aperta
#424 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
node.js, typescript

Direzione di ricerca

Inizia in node_modules/@node-escpos/core/dist/index.cjs, in corrispondenza dell’implementazione di close, e confronta l’API dell’adapter mostrata nell’issue. Riproduci il problema nella chiusura dell’adapter, quindi verifica che l’adapter di rete possa essere chiuso tramite il metodo disponibile senza interrompere flush o la gestione degli errori. Il lavoro è completato quando una connessione alla stampante può essere chiusa senza questo TypeError.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

First of all, I am just a hobby programmer :)

So basically this is my function.
I have an order which has many order_pos. From the order_pos i can get the corresponding printer (different item different printer)
For your information, i am generating an image which is printed. So i dont have to worry about encoding (like my names show) can print all fonts I want and all sizes I want.
But this is just a side note.

static async printOrder(order: Order) {
    PrintingService.splitOrderToPrintRequest(order).then(pr => {
      for (let printerInfo of pr) {
        (new Network(printerInfo.printerAddress)).open((x, device) => {
          PrintingService.getOrderFromIDAndPrinters(order.id, printerInfo.id).then(realOrder => {
            if (!realOrder) {
              throw new Error("Order is null")
            }
            try {
              // @ts-ignore
              const printer = new Printer(device, { encoding: "cp437" })
              printer.image(new fickEncodings(realOrder, false).toImage()).then(p => {
                p.cut;
                p.close()
            })
            }
            catch (err) {
              console.log(err)
            }
          })

        })
      }
    })
  }

You can see i am using the inteded way in the function. But i get following error.

node_modules\@node-escpos\core\dist\index.cjs:1167
    return new Promise((resolve, reject) => {
           ^
TypeError: this.adapter.close is not a function

with a console.log(p) in runtime I did see that THE ADAPTER has no close() instead there is an end()
So I tried changing this part

  async close(...closeArgs) {
    await this.flush();
    return new Promise((resolve, reject) => {
      this.adapter.close((error) => {
        if (error)
          reject(error);
        resolve(this);
      }, ...closeArgs);
    });
  }

to this:

  async close(...closeArgs) {
    await this.flush();
    return new Promise((resolve, reject) => {
      this.adapter.end((error) => {
        if (error)
          reject(error);
        resolve(this);
      }, ...closeArgs);
    });
  }

So i dont know if this is happening to any of you. But with this change its working for me.
plus: i dont have any problems with Too much requests, the printjobs will just wait and print after each other. Magic..

Lingua principale
TypeScript
Stelle
1.6k
Fork
443
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di lsongdev/node-escpos

Tutte le issue di lsongdev/node-escpos

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.