lsongdev / lsongdev/node-escpos
[BUG]: usb.on is not a function
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 1.6k
- Forks
- 443
- PR merge metrics
- No merged PRs in 30d
Description
### 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. (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_
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the example entry point in index.js and inspect node_modules/escpos-usb/index.js at line 53, where usb.on is called. Reproduce the error with npm install followed by node index.js using Node.js 22. Done means the example no longer raises the TypeError when creating escpos.USB.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, nodejs
- Domain
- embedded-iot
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100