lsongdev / lsongdev/node-escpos

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

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

Beschreibung

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

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

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.

Bewertung

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

Neue Issues direkt in Ihr Postfach

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