0

JavaScript critical error at line 9, column 38 in http://localhost:52967/js/app.js\n\nSCRIPT1002: Syntax error

when call the below java script

const qrCodeScannerBtn = document.getElementById('Btn');
const qrCodeScannerText = document.getElementById('Text');
const qrCodePreview = document.getElementById('preview');

const scanner = new Instascan.Scanner({
  video: qrCodePreview,
  mirror: false
});
scanner.addListener('scan', content => {
  qrCodeScannerText.value = content;
  scanner.stop();
});
qrCodeScannerBtn.addEventListener('click', () => {
  if (scanner._scanner._active) {
    return scanner.stop();
  }
  Instascan.Camera.getCameras()
    .then(function(cameras) {
      if (cameras.length) {
        const camera = cameras[cameras.length - 1];
        scanner.start(camera);
        console.log(scanner);
      } else {
        alert('No cameras found.');
      }
    })
    .catch(function(e) {
      console.error(e);
    });
});
user3744961
  • 53
  • 1
  • 7
  • *"JavaScript critical error"* sounds like it's coming from IE? - If so the issue is that IE does not support arrow `=>` functions. – Alex K. Aug 07 '18 at 10:34

1 Answers1

1

MDN states that arrow functions (known as lambda expressions in other languages) feature in ECMAScript 6 has no support in IE, you need to use standard function keyword as replacement for arrow functions:

scanner.addListener('scan', function(content) {
  qrCodeScannerText.value = content;
  scanner.stop();
});

qrCodeScannerBtn.addEventListener('click', function () {
    // function body
});

Related issues:

Javasciprt syntax error on Internet Explorer

Syntax error in IE using ES6 arrow functions

Tetsuya Yamamoto
  • 24,297
  • 8
  • 39
  • 61