0

I am using a third party library which is using global location variable and it throw the error when run that js code using loadScript in lwc.

I wrote a few lines of below custom js code to run as static resource and I am printing the global variable to see the output.

Static resource file code

(function () {
  console.log('##Test: location output #::', location)
  console.log('##Test: window output #::', window)
  console.log('##Test: window.location output #::', window.location)
  })();

I also console the logs in lwc different lifecycle hooks.

renderedCallback() {
      console.log('location in lwc renderedCallback::', location);
       this.loadstaticresource();
}

on lwc "location" global variable print output correctly but inn static resource it's value is undefined

console output

console image

what to do so it doesn't print null for location variable, it prints value with window.global but in third party API I can't use that.

0

You must log in to answer this question.

Browse other questions tagged .