My static resource

My static resource

Trying to load this script using loadscript. Below is my code...

    import { api,track,LightningElement } from 'lwc';
        import {
        } from 'lightning/platformResourceLoader';
        import instascan from '@salesforce/resourceUrl/instascan';

    export default class QRCodeScanner extends LightningElement {
        @track instascanInitialized = false;

        renderedCallback() {
                this.instascanInitialized = true;
                loadScript(this, instascan)
                    .then(() => { 
                        console.log('hii then'+then);
                    .catch(error => {
                        console.log('hii error' +error);

Always getting the same thing in the console

Chrome Console tab

According to the console the catch block is getting executed. But in the network tab I see the static resource is been initialized properly!

Chrome Network tab

Please let me know why am I getting this error even if the static resource is been loaded and how do I resolve this?

1 Answer 1


Its not the problem with your implementation.

Instascan is not compliant with Locker service. A quick read from this article - Is there any way to validate a third party JavaScript library against Lightning LockerService?, and checking instascan library, below will be observations:

  • It has new function
  • It has eval() usage
  • It does not have global use strict

Comparatively JQuery is locker service compliant and will have no problem loading in LWC.

  • 1
    can you suggest a library which is compliant with the locker service and can be used for QR code scanning? Oct 21, 2019 at 11:07
  • 1
    check quaggajs! i am trying to build the scanner component in salesforce through it. Oct 22, 2019 at 11:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.