yeah, bunch of people often forget this. why would someone invent firearms in a fantasy world where you have magic, you have wizards that can use firebals or lightning bolts or something (if magic in that setting alows fors such spells ofc), maybe you can even enchant regular arows so they can do all sorts of crazy stuff. early, primitive firearms would be very expensive, slow and impractical and would not like offer any advantages over magic.
"Why would someone invent firearms in a fantasy world where you have magic?"
Because not everyone can use magic. Actually if you think about it, a world where someone can throw fireballs and others can't, would be a very fruitful place for scientific progress. Non-mages would want to level the playfield and seek other paths to power.