kozakdenys / qr-code-styling

Automaticly generate your styled QR code in your web app.
https://qr-code-styling.com
MIT License
1.56k stars 497 forks source link

XMLHttpRequest is not defined - Node #238

Closed MikeCarbone closed 1 month ago

MikeCarbone commented 1 month ago

How can I avoid this? Only triggered when I include an image. I'm adding the jsdom and nodeCanvas library too. Anything else I can do? This error gets triggered in both Next.js API and Express

const options = {
      width: 800,
      height: 800,
      data: `data123`,
      image: "https://image-url.png",
      dotsOptions: {
          color: "#212121",
          type: "rounded"
      },
      backgroundOptions: {
          color: "#ffffff",
      },
      imageOptions: {
          crossOrigin: "anonymous",
          margin: 20
      }
 }

  const qrCodeImage = new QRCodeStyling({
    jsdom: JSDOM,
    nodeCanvas, // this is required
    ...options,
    imageOptions: {
        saveAsBlob: true,
        crossOrigin: "anonymous",
        margin: 20
    }
  });
kozakdenys commented 1 month ago

Hi @MikeCarbone, thanks for opening this issue, I am looking into this 👀

kozakdenys commented 1 month ago

@MikeCarbone no luck for now, I will try to fix it tomorrow morning

MikeCarbone commented 1 month ago

Thank you for looking into this @kozakdenys ! Let me know if I can help with more details

kozakdenys commented 1 month ago

Hi @MikeCarbone the issue should be fixed in v1.8.1 🎉 Also, I have added an example to this repo You can clone, run npm i, npm run build, and npm start to get generated QRs. If any problem, please reopen this issue

MikeCarbone commented 1 month ago

Can confirm it's working now. Thank you for your quick work on this @kozakdenys!