Remove item from diagram

please tell me how to programmatically remove an element from the diagram. I use the Remove method, the element remains on the diagram and an error appears in the console. Redrawing the diagram does not help.

remove() method:

should work correctly in this case.
Here is an example:
If the problem still occurs for you could you please, provide a complete demo or a code snippet where the problem can be reconstructed.