Danny Reagan posted an excellent answer for the classical DnD Magic scenario, although we can also watch two other factors:
Development of reliable gunpowder was freaking hard
Alchemists have to experiment with burning and explosives for years and try ever new combinations of getting an explosive reaction, all of which will lead to explosives first and afterwards bring about the idea of using it as the base for cannons. This whole development process will only likely progress if the intermediate goals (heavy burning substance, explosives, unreliable cannons) will already provide any merit. If your magical world already has cheap and safe means of using magic for mining operations and other places where explosives would be needed, it is unlikely someone will do the ludicrous research of highly unstable potions which are hard to handle, hard to dosage and really dangerous for the user...
And without this preliminary steps, it could be possible no one ever invested big resources into the research of explosives - and the resulting application of explosives in the form of fuel for cannons was in reach to be considered.
Magic crossbows and catapults could be better than guns
If you only user Magic in a direct approach with wizards walking around the battlefield throwing fireballs, this will most likely fail in the face of imperialistic warfare, where quantity is the deciding factor on a huge scale. But wizards on the front-lines would be like scientists and technicians using their inventions in battle. If the magic could be applicable to make artifacts, like self-reloading catapults. Magically enhanced projectiles for crossbows, or personal shielding devices for soldiers. If any of these artifacts could be produced beforehand in a big scale, or could be charged by a few wizards before the battle, a few wizards could be enough to provide the army with the means of heavy artillery or personal crossbow-guns with exploding bolts.
Special anti gun magic could be devastating
Another killing blow for guns on the battlefield could be if wizards developed special spells against fire-weapons. It could be an area-effect spell, which makes the air highly flammable, resulting in every shot fired blowing up the user. Or it could be a rain of sparks, which could easily ignite gunpowder reserves blowing everyone up. Or it could be a rune of humidity and rainfall, making everyone soaking wet and rendering all forms of early gunpowder completely useless.
Especially if some magicians have a way of letting your gun explode in your hands and will win two minor battles with it, you will have a hard time finding soldiers who would even want to carry a gun, which is a ticking time-bomb only waiting for a wizard.
Expensive Area-of-effect spells against guns could render them useless for a large-scale army, but still keep them interesting for hunting or single warriors, who hope the wizard won't cast an expensive AOE spell against guns when only a handful soldiers in the army carry guns. It could be an interesting gamble to carry a gun in this world - possibly fatal for the user if they meet the wrong wizard, but otherwise an impressive weapon... Death defying wildwest-like gunslingers, always on the lookout for wizards, their nemesis.