soldair / node-qrcode

qr code generator
MIT License
7.46k stars 621 forks source link

When i am making live my server its giving error #366

Open Ahahrukh opened 2 months ago

Ahahrukh commented 2 months ago

![Uploading Screenshot 2024-07-21 173735.png…]()

chrisroode commented 1 month ago

Hello! I just saw this issue, and I don't see the screen shot, but it sounds similar to a problem I am having. I just installed QRCode on my server to test it out and right out of the box, when running a Jest Test, it came back with the following error:

ReferenceError: TextEncoder is not defined at new ByteData (./node_modules/qrcode/lib/core/byte-data.js:6:21) at buildSingleSegment (./node_modules/qrcode/lib/core/segments.js:262:14) at ./node_modules/qrcode/lib/core/segments.js:286:16 at Array.reduce ()

When I looked at the source file byte-data.js, I noticed that line 6 or 7 references TextEncoder() as a global constant.

I added on line 2: const util = require('util')

and changed line (6 or 7) to this.data = new util.TextEncoder().encode(data)

And the code stopped crashing. I know my hot fix is going to lead to deployment issues, and I am not sure much more of the working of this package, but I would be willing to help work on this issue, just might need a little guidance. I would rather use the dependency directly than making a personal fork, fixing, and throwing it in my codebase somewhere.

Is this an issue others are facing?