lsongdev / node-escpos

🖨️ ESC/POS Printer driver for Node.js
https://npmjs.org/escpos
Other
1.38k stars 423 forks source link

TypeError: usb.on is not a function #376

Closed fillahfirdausyah closed 2 years ago

fillahfirdausyah commented 2 years ago

Hello, i'v tried and use example code, and igot error like this

TypeError: usb.on is not a function.

My code : const escpos = require("escpos"); escpos.USB = require('escpos-usb');

const device = new escpos.USB(1046, 20497); // const device = new escpos.RawBT(); // const device = new escpos.Network('localhost'); // const device = new escpos.Serial('/dev/usb/lp0'); const printer = new escpos.Printer(device);

console.log(device)

device.open(function (err) { printer .font("a") .align("ct") .style("bu") .size(1, 1) .text("The quick brown fox jumps over the lazy dog") .text("敏捷的棕色狐狸跳过懒狗") .barcode("1234567", "EAN8") .qrimage("https://github.com/song940/node-escpos", function (err) { this.cut(); this.close(); }); });

sam-lex commented 2 years ago

this happens on windows 10

if you're in a rush like me, a hacky-temporary workaround would be to go into the node_modules/escpos-usb/index.js and comment out usb.on ... part.

Then you'll run into another problem, saying usb.removeAllListeners is not a function. I commented that part out as well. Then it works ok-ish.

I had already made an app with electron + express and stuff on Linux about a month ago. And just about 3 days ago I tested on a windows machine for the first time, and got these same errors... I still got another problem to work with, which is the image I generate for it to print seems to "not fit" all of a sudden..

It seems to be somewhat related with this.. idk https://github.com/MadLittleMods/node-usb-detection/issues/77

Anyways.. good luck

romaia commented 2 years ago

This actually seem to be related with a major release of usb [1]

From what I checked, this project didn't pin the dependency [2], and it was working fine with version 1.9.2

Using yarn set resolution usb@npm:* 1.9.2 --save for now fixed this for me

[1] https://www.npmjs.com/package/usb [2] https://github.com/song940/node-escpos/blob/v3/packages/usb/package.json#L10

fillahfirdausyah commented 2 years ago

this happens on windows 10

  • on linux - ubuntu it's working fine.

if you're in a rush like me, a hacky-temporary workaround would be to go into the node_modules/escpos-usb/index.js and comment out usb.on ... part.

Then you'll run into another problem, saying usb.removeAllListeners is not a function. I commented that part out as well. Then it works ok-ish.

I had already made an app with electron + express and stuff on Linux about a month ago. And just about 3 days ago I tested on a windows machine for the first time, and got these same errors... I still got another problem to work with, which is the image I generate for it to print seems to "not fit" all of a sudden..

It seems to be somewhat related with this.. idk MadLittleMods/node-usb-detection#77

Anyways.. good luck

oh wow, for now it's working. thanks

peteruithoven commented 2 years ago

For npm using folks: As of NPM v8.3 you can override the version in your package.json by adding an overrides section:

"overrides": {
  "usb": "^1.9.2"
}

For earlier versions we noticed you can also install usb as a direct dependency.

npm install usb@1.9.2

(Using version 1.9.2 as romaia advised)

flapili commented 2 years ago

Same issue and using usb@1.9.2 did not help :/

AppPilots commented 2 years ago

Same problem here... No solution at all.

flapili commented 2 years ago

Look like usb@1.9.2 doesn't existe (anymore?) https://www.npmjs.com/package/usb/v/1.8.8 Using 1.8.8 solved the issue

YovanggaAnandhika commented 2 years ago

For Fix The Problem Please Migrate To USB Version 2 @see https://github.com/node-usb/node-usb#migrating-to-v200 @see https://github.com/song940/node-escpos/pull/388

i am change node_module/escpos-usb like let { usb } = require('usb');

Like my pull request. please merger @song940

YovanggaAnandhika commented 2 years ago

please close this issue

Siyavash-Adib commented 1 year ago

This actually seem to be related with a major release of usb [1]

From what I checked, this project didn't pin the dependency [2], and it was working fine with version 1.9.2

Using yarn set resolution usb@npm:* 1.9.2 --save for now fixed this for me

[1] https://www.npmjs.com/package/usb [2] https://github.com/song940/node-escpos/blob/v3/packages/usb/package.json#L10

Thank a lot, it's working for me now

ferminc commented 1 year ago

I recommend you to use https://github.com/node-escpos/driver The song940 node-escpos is basically deprecated by now

Sent from my iPhone

On 27 Jun 2023, at 06:36, Siyavash-Adib @.***> wrote:



This actually seem to be related with a major release of usb [1]

From what I checked, this project didn't pin the dependency [2], and it was working fine with version 1.9.2

Using yarn set resolution @.**: 1.9.2 --save for now fixed this for me

[1] https://www.npmjs.com/package/usb [2] https://github.com/song940/node-escpos/blob/v3/packages/usb/package.json#L10

Thank a lot, it's working for me now

— Reply to this email directly, view it on GitHubhttps://github.com/song940/node-escpos/issues/376#issuecomment-1609140269, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ABUMSKPFTIG5SFV5I7HRE7LXNKSQHANCNFSM5KDEHS5A. You are receiving this because you commented.Message ID: @.***>

Joshjoyb commented 2 months ago

this happens on windows 10

  • on linux - ubuntu it's working fine.

if you're in a rush like me, a hacky-temporary workaround would be to go into the node_modules/escpos-usb/index.js and comment out usb.on ... part.

Then you'll run into another problem, saying usb.removeAllListeners is not a function. I commented that part out as well. Then it works ok-ish.

I had already made an app with electron + express and stuff on Linux about a month ago. And just about 3 days ago I tested on a windows machine for the first time, and got these same errors... I still got another problem to work with, which is the image I generate for it to print seems to "not fit" all of a sudden..

It seems to be somewhat related with this.. idk MadLittleMods/node-usb-detection#77

Anyways.. good luck

After doing this, I'm getting another error message that goes: "LIBUSB_ERROR_NOT_SUPPORTED" - what should I do?

sam-lex commented 2 months ago

After doing this, I'm getting another error message that goes: "LIBUSB_ERROR_NOT_SUPPORTED" - what should I do?

I would recommend you check out this one instead https://github.com/node-escpos/driver or some other solutions from other comments.

I myself am not using it anymore, so I have no idea. But regarding your error LIBUSB_ERROR_NOT_SUPPORTED, it's listed in here: https://github.com/lsongdev/node-escpos/blob/v3/packages/usb/README.md