Ironically, adding onto my last comment, the realism of ranged weaponry tending to be superior to that of melee is hamstringed by not actually being realistic.
As noted, without any mechanical meaning behind damage types, nearly all martial attacks are mechanically identical with the only difference being the range at which they can be applied, which as a result means higher range is always better regardless of the circumstances.
Even with some of the other suggestions here, that issue isn't really resolved. Punishing shooting in melee range of an opponent doesn't go far enough in making up the difference simply because most aren't going to be just sitting still facetanking when trying to attack at range; you may as well just fight with melee at that point for all it matters.
But, with damage types mattering, the realism goes up. Ranged weaponry on the whole is generally only going to be able to deal piercing damage. And in a fantasy world, its not unrealistic to say that fantasy creatures will have distinct resistances, if not active defenses, against such damage.
Ranged then becomes powerful and optimal when not resisted, and is balanced out by being suboptimal when it is.
And moreover, what this then lets you do is justify to players actually using both range and melee on one character, fulfilling the classic fantasy of Archer characters, which almost all of which seldom use only their bow.
Hawkeye, Legolas, Robin Hood, etc all swap into melee weapons when the time calls for it. With Ranged weaponry being as so shallowly powerful as they are in 5e, you can't actually emulate those characters without gimping yourself.