Hacktoberfest 2026: die Issues, die Maintainer für den Oktober markiert haben – offen und einsteigerfreundlich. Hacktoberfest-Issues durchsuchen

[BUG]: usb.on is not a function

Offen
#441 5 Kommentare 1 Reaktion 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Anfängerfreundlichkeit
38/100
Issue-Typ
Bug
Klarheit
Größtenteils klar
Aktivitätsstatus
Veraltet
Tech-Stack
javascript, nodejs
Bereich
embedded-iot

Rechercherichtung

Beginne mit dem Beispiel-Einstiegspunkt in index.js und untersuche node_modules/escpos-usb/index.js in Zeile 53, wo usb.on aufgerufen wird. Reproduziere den Fehler mit npm install gefolgt von node index.js unter Node.js 22. Als erledigt gilt die Aufgabe, wenn das Beispiel beim Erstellen von escpos.USB keinen TypeError mehr auslöst.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

bug
Description of the bug
\node_modules\escpos-usb\index.js:53
  usb.on('detach', function(device){
      ^

TypeError: usb.on is not a function
    at new USB (D:\GolandProjects\testprint\usb_printer_project\usb_printer_project_nodejs\node_modules\escpos-usb\index.js:53:7)
    at Object.<anonymous> (D:\GolandProjects\testprint\usb_printer_project\usb_printer_project_nodejs\index.js:5:16)    
    at Module._compile (node:internal/modules/cjs/loader:1565:14)
    at Object..js (node:internal/modules/cjs/loader:1708:10)
    at Module.load (node:internal/modules/cjs/loader:1318:32)
    at Function._load (node:internal/modules/cjs/loader:1128:12)
    at TracingChannel.traceSync (node:diagnostics_channel:322:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:219:24)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:170:5)
    at node:internal/main/run_main_module:36:49

Node.js v22.12.0
 "escpos": "^3.0.0-alpha.6",
 "escpos-usb": "^3.0.0-alpha.4"
Steps To Reproduce

直接使用示例

npm init -y
npm install escpos escpos-usb
node index.js
const escpos = require("escpos");
// install escpos-usb adapter module manually
escpos.USB = require("escpos-usb");
// Select the adapter based on your printer type
const device = new escpos.USB();
// const device  = new escpos.Network('localhost');
// const device  = new escpos.Serial('/dev/usb/lp0');

const options = { encoding: "GB18030" /* default */ };
// encoding is optional

const printer = new escpos.Printer(device, options);

device.open(function (error) {
    printer
        .font("a")
        .align("ct")
        .style("bu")
        .size(1, 1)
        .text("The quick brown fox jumps over the lazy dog")
        .text("敏捷的棕色狐狸跳过懒狗")
        .barcode("1234567", "EAN8")
        .table(["One", "Two", "Three"])
        .tableCustom(
            [
                { text: "Left", align: "LEFT", width: 0.33, style: "B" },
                { text: "Center", align: "CENTER", width: 0.33 },
                { text: "Right", align: "RIGHT", width: 0.33 },
            ],
            { encoding: "cp857", size: [1, 1] } // Optional
        )
        .qrimage("https://github.com/song940/node-escpos", function (err) {
            this.cut();
            this.close();
        });
});

Additional Information

No response

Vorherrschende Sprache
TypeScript
Sterne
1.6k
Forks
442
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus lsongdev/node-escpos

Alle Issues in lsongdev/node-escpos

Ähnliche Issues

Weitere Issues zu TypeScript

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.