I am trying to load several js files in my LWC. But 3 out of the 4 files are failing to load and I can't figure out why.

Here's my code:

import { LightningElement } from 'lwc';
import { loadStyle, loadScript } from 'lightning/platformResourceLoader';
import MY_RESOURCES from '@salesforce/resourceUrl/my_resources';

export default class MyWidgetDs extends LightningElement {
    connectedCallback() {
            loadScript(this, MY_RESOURCES + '/some_folder/myFirstFile.js').catch(error => {
                console.log('p1 failed');
            loadScript(this, MY_RESOURCES + '/some_folder/mySecondFile.js').catch(error => {
                  console.log('p2 failed');
            loadScript(this, MY_RESOURCES + '/some_folder/myThirdFile.js').catch(error => {
                   console.log('p3 failed');
            loadScript(this, MY_RESOURCES + '/some_folder/myFourthFile.js').catch(error => {
                   console.log('p4 failed');
        ]).then(value => {
            console.log('all loading of resources is complete');
        }).catch(error => {
            console.log('ERROR IS ' );

What I get in the console is this:


So it appears to me that p2 is loading correctly but how do I see what the issue is with the loading of the other 3 promises?

Also am I not supposed to see value in the then. portion? All of the values come as undefined again. Shouldn't p2 have a value?

  • Why are you using individual catch blocks for each loadResource? wont promise all handle it? – Pranay Jaiswal Nov 15 '19 at 18:27
  • @PranayJaiswal I was trying to see if all of the files were failing or if any were managing to load. – Arthlete Nov 15 '19 at 18:28

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.