I'm reminded of the Guardians of the Flame series, where some college kids from Earth are Isekai'd to a fantasy world (long before Isekai was a well known term, because it's really nothing new, just as John Carter...) and eventually, the Engineering student was like "Hey, let's make guns!".
With their technological edge, they went to war with the entire institution of slavery in the world, but eventually the slavers got tired of it and went to some Wizards to come up with their own answer to guns- using magic to reinforce an iron sphere so it wouldn't break, they filled it with water and boiled it over a high flame and came up with some strange powder that exploded when it came into contact with water, so their "guns" would hit the powder with a squirt of water, of all things.
Anyways, I think it illustrates a good point. Any new innovation is going to copied, adapted, and defended against. Pathfinder 1e had spells and a few magic items that both supported and negated the advantage of firearms. Spells that could dampen powder, guns that produced their own ammo, and magic can already produce bulletproof barriers, so it's inevitable that enchanted flak jackets and bullet ward charms could go on the market. Sure, you could make better and better guns, but magic has far fewer limits than technology in games like D&D.
I think this is what probably happened behind the scenes in the Forgotten Realms- in early 2e, firearms were readily available and spreading. By the time of 5e, they've become rarely seen relics (I believe Dragon Heist offers the opportunity to acquire some smoke powder). Gond was chastised by his fellow gods for unleashing this technology sure, but once the secret was out there, it wasn't like you could put the genie back in the bottle. However, either because of their cost, unreliability, or other factors, up to and including adaptations to firearms (and possibly the fact you still needed magic weapons to harm certain creatures as the game slowly moved past foes with "+1 or better magic weapons to hit", to "DR/15 magic", to "DR/5 magic" to "resistant to non-magic weapons"), they just fell out of favor.
Because magic outpaces guns. A Wand is more lethal than a gun (There was a chapter in "Voyage of the Princess Ark" in Dragon magazine where the main character was, for all intents and purposes, challenged to a gunfight at high noon. He brought his Wand of Lightning Bolts. Guess who won?).
Even as Wands became less spammable (the old Wand of Magic Missiles went from having 5 charges to 7 daily), casters got cantrips, first piddly ones that did d3 damage, now you have Firebolts that can do up to 4d10, and let's not forget the Warlock's Eldritch Blast, to the point that a spellcaster would dominate any gunfight unless there was some kind of "null-magic" around to prevent it.
Huh. I wonder if that's why some people grumble about cantrips. It's too much like having arcane casters be gunslingers?