Error when swapping a component

Hey there, I’m getting an error when swapping a component using swapComponent. I’m getting a new component by getNodeById and then swapping. It’s working for some components but others it doesn’t even though they exist and the component node can fetch?

Have you seen this issue before? Error: in get_parent: The node (instance sublayer) with id "I13380:55445;12984:28968" does not exist
    at InstanceNode.get_parent [as parent] (eval at <anonymous> (eval at createScopedEvaluatorFactory

Example code
Screen Shot 2022-06-24 at 3.01.31 pm

const newComponent = figma.getNodeById(replacementNodeId);
                    if(newComponent) {

change the second line to

if(newComponent && !newComponent.removed)
1 Like