In my case I got this error since I was passing data-bs-target attribute and left the # from the target string.
data-bs-target
#
So basically any incorrect reference to the ID of the modal will result in this error.