+ Start a Discussion
Jigar.LakhaniJigar.Lakhani 

LWC > Load Script > Static Resource JS File > Not Working

Hi Folks,

I am building a LWC to load external JS script file in LWC. However whenever loadScript function is executing it is failing to load and there is not error received.

LWC
import { LightningElement, track  } from 'lwc';
import { loadScript } from 'lightning/platformResourceLoader';
import BrandfolderJS from '@salesforce/resourceUrl/BrandfolderJS';

export default class brandFolderLink extends LightningElement {
	
    @track blnBrandfolderJSInitialized = false;
    
    renderedCallback() {

        if (this.blnBrandfolderJSInitialized) {
            return;
        }
        this.blnBrandfolderJSInitialized = true;

        loadScript(this, BrandfolderJS)
        .then(() => {
            alert('success.......');
        })
        .catch(error => {
            alert('failed.....'+error);
        });
    }
	
}

JS file from Static Resource - Brandfolder JS (https://cdn.brandfolder.com/bf.min.js)
I have created JS file as static resource (BrandfolderJS) and using it in LWC.

LWC is added to App Builder Page/Home Page and trying to load, however it is going to catch block in loadScript method without any error. Error variable is undefined.

Can you please help?

Thank you,
Jigar Lakhani

Divesh JaitleyDivesh Jaitley
I am having sames issues. Hope anyone got solution to this.
James KeoghJames Keogh
Hi @Jigar.Lakhani,

Have you figured out the solution to this problem?

Thanks,
James
Jigar.LakhaniJigar.Lakhani
Hi,

No, Don't have any solution.
However it is not from salesforce, the issue is with Brandfolder JS Library.

Other Libraries are working fine with LWC.

Thank you,
Jigar
Nicolás GomezNicolás Gomez
Hi, I have the same problem. So there isn't any solution for this? The library can't be used on salesforce?
IT Support EnessIT Support Eness
Having the same problem here with a different library. Does not load and error is undefined. Any solution yet?
klthawklthaw
same problem with amazon connect streams js file.
https://github.com/amazon-connect/amazon-connect-streams

any solutions?
Thanks
chris coates 19chris coates 19
Jigar, do you have a link to an example script library which does load ok, i think there might be a additional notation needed for LWC, but not having got anything to work so far either, seeing a working example would be great (and easy to compare the file structure).
IT Support EnessIT Support Eness
How can we inform SF that https://developer.salesforce.com/docs/component-library/documentation/en/lwc/lwc.js_third_party_library is erroneous regarding the catch method?
Omkar Deokar 2Omkar Deokar 2
@jigar.Lakhani  was this issue ever resolved? 
Was it something to do with salesforce's security updates regarding serving static resources via vf domain rather than lightning domain?
refer this StakeExchange (https://salesforce.stackexchange.com/questions/327127/unable-to-load-external-js-scirpt-like-moment-js-after-winter-opt-in-update-rela)
Vivek SVVivek SV
I was able to fix this issue by switching the Security Level on the Experience Builder to "Relaxed CSP" and by turning off Lightning Locker