2

In Lightning Experience, calls to createComponent() or createComponents() will return as failures if there is an error during the creation of any one of the individual components. The error messages for all components will be the same: "No COMPONENT named markup://c:ComponentDoesNotExist found" (even if the component was actually a lightning:badge for instance)

I've even seen this behaviour happening with calls to createComponent() made from separate components if timing is right.

Does this make any sense? The behaviour in Communities is different - only the missing component will return a failure, and the others will succeed and be rendered on the page.

The following component will output two identical error messages to the console and render no badge component. Tested in both Spring and Summer 19.

Component

<aura:component implements="flexipage:availableForAllPageTypes,forceCommunity:availableForAllPageTypes" access="global" >
    <aura:handler name="init" value="{!this}" action="{!c.doInit}" />
    {!v.body}
</aura:component>

Controller

({
    doInit: function(component, event, helper) {
        $A.createComponent(
            'lightning:badge',
            {label:'Hello world'},
            function(newCmp, status, errorMessage) {
                if (status === 'SUCCESS') {
                    let body = component.get('v.body');
                    body.push(newCmp);
                    component.set('v.body', body);
                } else {
                    console.error(errorMessage);
                }
            }
        );
        $A.createComponent(
            'c:ComponentDoesNotExist',
            {},
            function(newCmp, status, errorMessage) {
                if (status === 'SUCCESS') {
                    let body = component.get('v.body');
                    body.push(newCmp);
                    component.set('v.body', body);
                } else {
                    console.error(errorMessage);
                }
            }
        );

    }
})

Alternative doInit using createComponents()

({
    doInit: function(component, event, helper) {
        let componentsToCreate = [
            ['lightning:badge', {label:'Hello world'}],
            ['c:ComponentDoesNotExist', {}]
        ];

        $A.createComponents(
            componentsToCreate,
            function (newCmps, status, errorMessage) {
                if (status === 'SUCCESS') {
                    component.set('v.body', newCmps);
                } else {
                    let body = [];
                    newCmps.forEach(function(cmp) {
                        if (cmp) {
                            body.push(cmp);
                        }
                    })
                    component.set('v.body', body);
                    console.error(errorMessage);
                }
            }
        );

    }
})
1

i Just tried to reproduce your issue using above code, it works fine for me. here is my tested code. i only modified the variable names in 2nd component creation function.

setesting.cmp

<aura:component implements="flexipage:availableForAllPageTypes,forceCommunity:availableForAllPageTypes" access="global" >
<aura:handler name="init" value="{!this}" action="{!c.doInit}" />
{!v.body}
</aura:component>

setestingController.js

({
doInit: function(component, event, helper) {
    $A.createComponent(
        'lightning:badge',
        {label:'Hello world'},
        function(newCmp, status, errorMessage) {
            if (status === 'SUCCESS') {
                let body = component.get('v.body');
                body.push(newCmp);
                component.set('v.body', body);
            } else {
                console.error(errorMessage);
            }
        }
    );
    $A.createComponent(
        'c:setesting1',{},
        function(newCmp1, status, errorMessage) {
            if (status === 'SUCCESS') {
                let body1 = component.get('v.body');
                body1.push(newCmp1);
                component.set('v.body', body1);
            } else {
                console.error(errorMessage);
            }
        }
    );

}
})

setesting1.cmp

<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
 <lightning:badge label="component from 2nd conponent"/>
</aura:component>

result imag

| improve this answer | |
  • The key with this issue is that the 2nd component (setesting1.cmp) doesn't exist. If you delete that component or just change the name inside the createComponent() call, both creates seem to fail – stucameron May 9 '19 at 13:02

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.