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
Asad Mahmood 6Asad Mahmood 6 

Third party js library will not load in lwc

Hi guys, 

I have been trying to third party js file called oidc-client.js from static resource and unfortunately will not load the script. However, when I try to load jquery js file, it will load. I can see in the network tab of Google chrome developer tools that oidc js was loaded successfully. 

There's no error stack other than undefined. 

I downloaded the file from https://github.com/IdentityModel/oidc-client-js

​​​​​​Any ideas why It won't loadscript?? 

Sorry I am not leaving any code snippet because I am raising this issue using my phone. 

Many thanks
Asad
​​​​​​
​​​
AbhishekAbhishek (Salesforce Developers) 
Hi Asad,

You can use third-party JavaScript libraries with Lightning web components. For example, use a library with interactive charts and graphs or one to reduce code complexity.

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

The above blog have complete information.

I hope you find the above information is helpful. If it does, please mark as Best Answer to help others too.

Thanks.
Asad Mahmood 6Asad Mahmood 6
import { LightningElement } from "lwc";
import { loadScript } from 'lightning/platformResourceLoader';
import oidc from '@salesforce/resourceUrl/oidc';

export default class MainComponent extends LightningElement {
renderedCallback() {
    Promise.all([
        loadScript(this, oidc),
    ])
    .then(() => {
      alert('oidc loaded');
    }).catch(err => {
      alert('oidc not loaded')
      console.log(err);
    });
  }
}

Hi Abishek,

Please see above code, the library will not load, it works fine in classic page but not in LWC.

If you have time then could you please try from your side in sample app to see if it loads
here's the link: https://github.com/IdentityModel/oidc-client-js/tree/dev/dist
 
AbhishekAbhishek (Salesforce Developers) 
Let me check and if I find anything useful let you.
Naresh Vaddepallli GNaresh Vaddepallli G
I solved similar issue reported here with the help from https://salesforce.stackexchange.com/questions/317576/how-do-i-actually-use-an-imported-js-script-in-my-lwc
Surya Rama PedapatiSurya Rama Pedapati
Hi @Asad, I'm using the same library in LWC, and I'm getting the same error "undefined" while loading the .js files. Do you remember how the issue was resolved back then ?
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