Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Html5QrcodeScanner is not a constructor #270

Closed
ayubUOL opened this issue Aug 9, 2021 · 6 comments
Closed

TypeError: Html5QrcodeScanner is not a constructor #270

ayubUOL opened this issue Aug 9, 2021 · 6 comments

Comments

@ayubUOL
Copy link

ayubUOL commented Aug 9, 2021

The bug
I'm using Angular 12 toolkit with Ionic framework.
Followed the documentation but didn't understand why this error appears.
Used both npm command to installed the related modules plus I've linked JS file from assets folder as well but both ways it's not working.

Import from npm
import Html5QrcodeScanner from 'html5-qrcode'

Manual import to use JS file
declare var require: any; var Html5QrcodeScanner = require('html5-qrcode');

function onScanSuccess(decodedText, decodedResult) { // handle the scanned code as you like, for example: console.log(Code matched = ${decodedText}`, decodedResult);
}

function onScanFailure(error) {
  // handle scan failure, usually better to ignore and keep scanning.
  // for example:
  console.warn(`Code scan error = ${error}`);
}

let html5QrcodeScanner = new Html5QrcodeScanner(
  "reader", { fps: 10, qrbox: 250 }, /* verbose= */ false);
html5QrcodeScanner.render(onScanSuccess, onScanFailure);`

Screenshot 2021-08-09 at 4 39 40 PM

Looking forward for guidance to improve my code. Thank you
@mebjas @gurubobnz @esin @dampee @jdtimmerman

@dampee
Copy link
Contributor

dampee commented Aug 9, 2021

I don't understand why you mention people. It might be me, but I think it is quite rude to do so. Certainly if people have not requested to make sure you ping them if you post something. Furthermore, I have hardly any experience with Angular.

Unsubscribing from this issue to make sure I am not updated from any further comments.

@dampee
Copy link
Contributor

dampee commented Aug 9, 2021

... That said, for our project, bundling was the issue. And we solved it using webpack externals.

@ayubUOL
Copy link
Author

ayubUOL commented Aug 9, 2021

My sincere apologies, I mentioned you because I saw that you are contributor in making of this project.
Thank you for telling me about Webpack externals.

@mebjas
Copy link
Owner

mebjas commented Oct 17, 2021

Can you verify with latest version of code with npm update?

(I'll add more documentation later)

@mebjas
Copy link
Owner

mebjas commented Oct 23, 2021

This should have been fixed in latest version - v2.1.0

Please reopen if this is still an issue.

@mebjas mebjas closed this as completed Oct 23, 2021
@elazarza
Copy link

this is still an issue with importing the JS file directly in angular.json (not using the npm package)
im using version 2.3.6
using this code:

declare var require: any; var Html5QrcodeScanner = require('html5-qrcode');
function onScanFailure(error) {
  // handle scan failure, usually better to ignore and keep scanning.
  // for example:
  console.warn(`Code scan error = ${error}`);
}
function onScanSuccess(decodedText, decodedResult) { // handle the scanned code as you like, for example:
  alert(decodedText + ' ' +decodedResult)
}
let html5QrcodeScanner = new Html5QrcodeScanner(
  "reader", { fps: 10, qrbox: 250 }, /* verbose= */ false);
html5QrcodeScanner.render(onScanSuccess, onScanFailure);

and getting the same error:
qrscanner-dialog.component.ts:13 Uncaught TypeError: Html5QrcodeScanner is not a constructor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants