0

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() {
        Promise.all([
            loadScript(this, MY_RESOURCES + '/some_folder/myFirstFile.js').catch(error => {
                console.log('p1 failed');
                console.log(error);
            }),
            loadScript(this, MY_RESOURCES + '/some_folder/mySecondFile.js').catch(error => {
                  console.log('p2 failed');
                  console.log(error);
              }),
            loadScript(this, MY_RESOURCES + '/some_folder/myThirdFile.js').catch(error => {
                   console.log('p3 failed');
                   console.log(error);
               }),
            loadScript(this, MY_RESOURCES + '/some_folder/myFourthFile.js').catch(error => {
                   console.log('p4 failed');
                   console.log(error);
               }),
        ]).then(value => {
            console.log('all loading of resources is complete');
            console.log(value);
        }).catch(error => {
            console.log('ERROR IS ' );
            console.log(error);
            console.log(error.message);
        })
    }
}

What I get in the console is this:

lwc_loading_of_resources_promise_failure

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 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 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.