[SalesForce] Definition does not exist while creating lightning component dynamically

While creating a lightning component dynamically getting error message

Definition does not exist on the client for
descriptor:markup://c:ComponentName

but error is getting resolved by making attributes and component global,
but i don't want to make my component global for some reasons.

Any help what to do ??

My code :
my component that i'm trying to create dynamically :

    <aura:component access="public">
<aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
<aura:attribute access="public" name="text" type="String" default=""/>
    {!v.text}
</aura:component>

my another component controller that is trying to create above component dynamically :

$A.createComponent("c:ComponentName", {
            'text' : 'my sample text'
        }, function(cmp, status, errorMessage) {
            if (status === "SUCCESS") {
                var cmpBody = component.get("v.cmpBody");
                cmpBody.push(cmp);
                component.set("v.cmpBody", cmpBody);
            }
            if (status === "INCOMPLETE") {}
            if (status === "ERROR") {}
        });

my component attribute(cmpBody) is defined as follows :

<aura:attribute name="cmpBody" type="Aura.Component[]">

Best Answer

Use namespace instead of c in $Lightning.use() and $Lightning.createComponent()

Related Topic