How to create new Sprite programatically?

I followed the hints in this thread: Cocos creator, create sprite with node dynamically - #3 by trungnt85 or even this tread: How Do I Create a cc.ProgressBar Programmatically? - #2 by chestermjr

yet the new sprite doesn’t show. Any idea why?

    let n = this.node.getChildByName("flipping_n")
    if (!n) { error('n==nil'); return; }

    resources.load('images/icon-dude/spriteFrame', SpriteFrame, (err: any, spriteFrame) => {
        if (err) { error(err.message || err); return; }
        var node = new Node();
        if (!node) { error('node==nil'); return; }
        let spriteComponent = node.addComponent(Sprite);
        spriteComponent.spriteFrame = spriteFrame;
        n.addChild(node);
        console.log("FRAME.name="+spriteFrame.name);
    });

The code runs to the end. The FRAME.name shows nicely: FRAME.name=icon-dude

check Node’s visibility and your camera configuration, it could be other reason too, but can’t tell directly from the code

I managed to show the new Label if a prefab clone is used:

            let prefab_n = this.node.getChildByName("lbl_test")
            var child_n = instantiate(prefab_n)
            child_n.position = new Vec3(0, 0, 0)
            var child_lbl = child_n.getComponent(Label)
            child_lbl.string = 'XXXXXXXXXXXXXXXXX'
            parent_n.addChild(child_n);

but when I create the Label from scratch then nothing shows up.
parent_n is the same in both cases.

            var child_n = new Node()
            child_n.active = true
            child_n.position = new Vec3(0, 0, 0)
            var child_lbl = child_n.addComponent(Label)
            child_lbl.string = 'XXXXXXXXXXXXXXXXX'
            parent_n.addChild(child_n);

I even tried to set extra properties to it:

            child_lbl.fontSize = 25
            child_lbl.lineHeight = 30
            var child_tr = child_n.addComponent(UITransform)
            child_tr.setContentSize(100,100)
            child_tr.setAnchorPoint(0.5,0.5)

but no luck. Any hints?

Please submit a demo so that we can investigate

FOUND the issue. There was something goofy in my scene. When I’ve created new scene then everything started to work. Thanks!