Skip to content

[BUG]: usb.on is not a function #441

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
lingyunzhizun opened this issue Apr 16, 2025 · 3 comments
Open

[BUG]: usb.on is not a function #441

lingyunzhizun opened this issue Apr 16, 2025 · 3 comments
Labels

Comments

@lingyunzhizun
Copy link

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

@AnSiwei
Copy link

AnSiwei commented Apr 20, 2025

去node_modules里把usb.on那一段注释掉就可以了

@clopezpro
Copy link

You have to directly change a code line but this is not yet integrated into the official version check #428

@clopezpro
Copy link

I have battled with this library, even in the types, but I manage to work thanks to the comments, Python's is another case

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants