1

I am trying to load this JS script: http://cdn.tagcommander.com/3468/tc_ENGIE_iframe.js So I downloaded it as static resource and use loadScript in LWC:

import { loadScript } from "lightning/platformResourceLoader";

connectedCallback() {
    loadScript(this, "/resource/selfcaretagcommander").then(res => {
          console.log("file selfcaretagcommander loaded");
          console.log("window.tC: ", window.tC);
          console.log("window.tC.inArray: ", window.tC.inArray);
          console.log("window.tc_vars_adapter: ", window.tc_vars_adapter);
        })
          .catch(e => {
            console.log("error: ", e);
            console.log("file selfcaretagcommander failed to load");
            console.log("window.tC: ", window.tC);
            console.log("window.tC.inArray: ", window.tC.inArray);
            console.log("window.tc_vars_adapter: ", window.tc_vars_adapter);
          });
}

It goes to the catch block with error undefined but I see that the beginning of the script has been loaded as I can see the "tC" variable and it's content but it seems that at some point it stops loading as the functions at the end are undefined.

2
  • 1
    Your code doesn't import static resources from the @salesforce/resourceUrl scoped module. Check this & this for sample code.
    – arut
    Jan 6 '21 at 8:57
  • 3
    Hi Ludodo, in addition to what @arut said, note that 3rd party library is always difficult to use in LWC because of LockerService. You can refer to this to check if the library use any unsupported API which will cause exception. Jan 6 '21 at 9:06

Your Answer

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

Browse other questions tagged or ask your own question.