function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ 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
Dmitry Bakovich 7Dmitry Bakovich 7

In my case, the issue was that Lightning Locker did not like the imported library. The solution was to enable Lightning Web Security.

https://developer.salesforce.com/docs/component-library/documentation/en/lwc/lwc.security_lwsec_intro

Brian Watts 21Brian Watts 21
I had a working 3rd party library when used in a `plain` LWC (extends LightingElement), but it didn't want to work when used in an LWC  that extends LightingModal.

I finally realized it was because I had been debugging with `Lightning Web Security` turned off.

Turning it on allows the loadScript function to work correctly in a LightningModal (but it makes debugging harder)
patrick devpatrick dev
I am facing the same problem. Is there any solution for this. I had used the mail back service for this but its not working.
APKYOLO COMAPKYOLO COM
capcut pro apk  (https://apkyolo.com/capcut/
Users have the freedom to merge many recordings into one to produce the whole video using KineMaster,
1mody.com
apkzar.com
kingsrom.com
apkzar.co
SForceBeWithYouSForceBeWithYou
My issue (not with ChartJS which was working fine, but with PptxGen JS) was resolved by enabling Lightning Web Security (LWS).

https://developer.salesforce.com/docs/component-library/documentation/en/lwc/lwc.security_lwsec_intro

Thank you Dmitry Bakovich 7!!

https://developer.salesforce.com/forums/?id=9062I000000XrWiQAK