I did some investigation and found that in Experience Editor key property was missing from
<code> element. This element is for Experience Editor. I found that "key" attribute was missing from the element and if I am adding the key attribute on element it was working fine.
There is post call happening which is going with some data when you are clicking on add to placeholder button and when I did check the value which was sending for that API call it was missing "plaholderKey" attribute and that was reason I was getting this error.
No having "key" attribute have many reasons like any of your JS code is removing it for some reason to make something in your front end and same JS you are using in Experience Editor so it is removing here also that should not happen. In that case you need to scan your JS code which is doing this.
In my case I am using VueJs for front end development and VueJs also use key attribute on element for some other stuff to work. And that was reason "key" attrbute was missing from element.
In my case I added few code updates in my VueJs framework as per given in Error in adding rendering from experience editor post and it works for me.
This may help if you are also having the similar issue.