Generate QR Code

Hello,

So I have seen this post https://www.wix.com/velo/forum/coding-with-velo/hello-corvid-how-can-i-add-qr-code-generator-api-to-my-website, and I (believe) have followed the guidelines to get a QR Code generation, but I am getting an error at this line …

$w ( “#vectorImage13” ). src = qr ; //LINE WITH ERROR MESSAGE

ERROR MESSAGE
Wix code SDK error: The “src” property cannot be set to “[object Object]”. It must be a valid SVG XML string or an SVG source starting with “http://”, “https://”, or "wix:vect

BACKEND CODE

// qrCode.jsw 
import QRcode from 'qr';

export function generateQRcode(toEncode) {
 let opts = {
        errorCorrectionLevel: 'H',
        type: 'svg',
        rendererOpts: {
            quality: 0.3
 }
 };
 return QRcode.toString(toEncode, opts, function (err, string) {
 if (err) throw err;
 return string;
 })
}

CLIENT SIDE CODE

import {generateQRcode} from 'backend/qrCode.jsw';
let codeToEncode = "MY-CODE"; //use your own code

//---------------------------------GENERATE QR
generateQRcode(codeToEncode)
.then(qr => {
$w("#vectorImage13").src = qr; //LINE WITH ERROR MESSAGE

console.log("QR IS", qr);
console.log("QR IS", qr);
console.log("QR IS", qr);

})

Any help would be great !

Have you remembered to put it inside the $w.onReady() (like in the linked example) ?

Hey JD, thanks for answering…

If that is the problem, I would have to appologize for my lack of knowledge. Your code is inside $w . onReady (() => {}., while mine is inside $ w . onReady ( function () {}, which I assumed was the same

Please let me know

It is the same.

Hello,

I took another look, and there is one difference between your code and mine, perhaps that is the problem

At the backend, while you use import QRCode from ‘qrcode’ ; I am using import QRCode from ‘qr’. That is because I have a “cannot find the module…” error, when I try using “qrcode”

Another thing that might help, when I test my code the $w ( “#vectorImage13” ). src element just dissapears

Any idea would be great

Did you add the NPM library to your project as J.D. points out in the original post that you linked to?

Hey, thanks for joining in,

Yes, actually I first learned about it in a post you answered in 2019 https://www.wix.com/velo/forum/coding-with-velo/how-to-create-unique-personal-id-qr-code

Here is the NPM library

Not sure if you used the same library from my old post, or used a different one. I see I installed one called qrcode , and the one you installed seems to be called qr .

You will need to follow the documentation of the library you installed ( qr NPM library?) to see how to import and use that library. The docs should have everything you need. Wix is unable provide support for external libraries.

Good point… I hope that is the issue, and I have installed a wrong library. It must be a dum mistake as everybody else has this code working fine

Both you and JD have been really helpfull

Thank you very much

Hi,

After installing the correct package from NPM, the problem was solved. Now the code works perfectly.

Thank you very very much @info51522 @yisrael-wix

Well, sadly It looks like I started cheering too fast…

QR code appears perfectly in PREVIEWED. However the code does not appear in PUBLISHED SITE.

Console log is showing me no error, and the path it shows me for the vectorimage is the same

Does anybody have any idea why qr code could normally appears in previewed, but not in published ??..I am really lost

Any help would be great

Can you post the live site URL?

Hello,

@J. D. have you had time to look into it ??
Please let me know when you do

Thanks !!

Sorry, I’ve missed your latest post.
It looks like that something got broken with the performance improvement rollout.
I’ll pass it to someone at Wix, but please prepare a regular page for example that doesn’t require registration and post the link here, so it will be easier to look into it.

Another point that maybe can solve the issue.
It looks like you put an image as placeholder instead of a shape.
Please try to use a shape and let us know if it works.

Hi,

The qrcode placeholder is a shape, as I followed instructions in your post. However there is an image in the section below it

In order to simplify qrcode testing, between preview and live, now there is a page https://www.noanestdigital.com/qrcodetesting

Thank you very much for the time you took on this issue

Hi Sebas,
Is the issue resolved now? I excluded your site from our performance rollout. We will investigate the issue and add your site back in when it’s fixed. Thanks!

Hello,

Today I saw qrcode issue was fixed. I thank you for that. Great support.

However, about an hour ago, I started having heavy issues, and I can’t work because I have two error messages. I just posted it…

Maybe it is something that has been changed…please let me know

As for the rollout, I would really ask you to include me ASAP to any performance improvement. I am a beginner in coding, so I need every performance help I can get

Thanks!

@marlowe-shaeffer in case the problems I am experiencing today are related with the exclution, I would ask you to be included again.

I can work on something else until qrcode issue is fixed.

Please let me know

Your site has been added back into the rollout, which should resolve the new errors. We will continue to investigate the original issue with the QR code. Thanks!