edi9999 / jsqrcode

[deprecated] Lazarsoft's jsqrcode as a node module, object oriented, and with tests
Apache License 2.0
278 stars 63 forks source link

Incorrect error thrown or assumed global?? #46

Closed azayneeva closed 6 years ago

azayneeva commented 6 years ago

When passing the incorrect format it throws this error

/node_modules/qrcode-reader/dist/index.js:3048
    if (!Image) {
         ^

ReferenceError: Image is not defined
    at QrCode.decode (/Users/user/Desktop/test/node_modules/qrcode-reader/dist/index.js:3048:10)
    at Server.router (/Users/user/Desktop/test/src/router.js:37:8)
    at emitTwo (events.js:125:13)
    at Server.emit (events.js:213:7)
    at parserOnIncoming (_http_server.js:602:12)
    at HTTPParser.parserOnHeadersComplete (_http_common.js:116:23)

this comes from this code

    if (!Image) {
      throw new Error("This source format is not supported in your environment, you need to pass an image buffer with width and height (see https://github.com/edi9999/jsqrcode/blob/master/test/qrcode.js)");
    }

I assume Image was originally required but it has been removed

edi9999 commented 6 years ago

In the browser, we already have an image parser (Image), so we directly use that if it exists.

In node, you have to use an image parser (image-parser / jimp / other).

The code was wrong :

if (!Image)

but it should have been

if (typeof Image === "undefined") {

but this is now fixed in v 1.0.3