Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Wrong function on network adapter close?

オープン
#424 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
node.js, typescript

調査の方向性

node_modules/@node-escpos/core/dist/index.cjs の close 実装から始め、issue に示されているアダプター API と比較します。アダプターのクローズに失敗する問題を再現し、その後、flush やエラーハンドリングを壊すことなく、利用可能なメソッドを使ってネットワークアダプターをクローズできることを確認します。この TypeError なしでプリンター接続をクローズできれば完了です。

索引モデルが issue の本文から書いたものです。

説明

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..

主要言語
TypeScript
スター
1.6k
フォーク
443
PR マージ指標
30日以内にマージされた PR はありません

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

lsongdev/node-escpos のほかの issue

lsongdev/node-escpos の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。