1

Time to time I am getting an undefined error when a few of JS scripts (static resources) are loaded. The error is faced only the first time the component is loaded. It means, after the error is faced if the component is closed and the page is refreshed then,the next time is working perfectly.

This is the piece of code:

    renderedCallback() {

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

    Promise.all([
        loadScript(this, FullCalendarJS + '/jquery.min.js'),
        loadScript(this, FullCalendarJS + '/moment.min.js'),
        loadScript(this, FullCalendarJS + '/theme.js'),
        loadScript(this, FullCalendarJS + '/fullcalendar.min.js'),
        loadStyle(this, FullCalendarJS + '/fullcalendar.min.css'),
    ])
        .then(() => {

        })
        .catch(error => {
            console.error({
                message: 'Error occured on FullCalendarJS',
                error
            });
        })

}

This is what the browser's console is shown when the error is faced, as we can see the console error message is printed, but at the same time, all the scripts appears with the status code 200...Does this make sense??

enter image description here

Any idea?

Note: Disabling the cache in the browser’s console** the error appears time to time** during the first time load, so it is not easy to replicate.

1 Answer 1

0

You are loading the scripts from the renderedCallback, since you haven't shared the whole component I can't be sure but I suspect you try to use something from those scripts before they are loaded.

You might want to set a second scriptsLoaded variable in your then handler and hold off on using those libraries until it is set.

1
  • There a two components, a parent an a child, child methods are only executed when a button in the parent is clicked. In this case, the loadscript error is faced when the component is rendered, so the user didn’t have time to click any button yet. Dec 17, 2021 at 21:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.