I didn't even realise this was a problem until recently; first character I played was a paladin so mostly attacked with a melee weapon, when I occasionally used ranged I either never got opportunity attacks or assumed enemies had a way to bypass them. Didn't realise it was because I had a bow.
That's such a weird design decision, as even while holding a ranged weapon you should still be able to make an unarmed strike (e.g- kick) at the very least. But since switching weapons is free in BG3 (just select melee or ranged attack and it happens before you even do it) there should be no reason the character can't just switch for an opportunity attack as well, we shouldn't need to do it manually (though having the option would be nice).