When you consider that they took forever to reload, we’re inaccurate, and probably terribly expensive, why would someone want that as opposed to a crossbow?
It took entire firing squads to stand in front of each other to reliably hit a target, when as far as I’m aware a bowman could be anywhere on the battlefield.
It seems to me like having a bow and arrow or a crossbow is more effective, so besides maybe cannons why were early guns so quickly able to replace arrow based projectiles
why would someone want that as opposed to a crossbow?
Because:
took forever to reload
... up to a minute, working slowly. This is comparable to the time needed to load a powerful crossbow. Well-drilled musketeers could load and fire in 20 seconds.
we’re inaccurate
Early guns such as hand cannons/handgonnes don't appear to have been very accurate. Pistols were also inaccurate. However, even these weapons could have a good chance of hitting a human-sized target out to perhaps about 30 metres. Guns with longer barrels were more accurate at longer ranges, but past about 70-100 metres, the unpredictable spin of the ball from a smoothbore gun would reduce the accuracy.
probably terribly expensive
Similar in price to a crossbow or composite bow, or cheaper.
The comparison with a crossbow isn't so unfavourable. One issue is that gunpowder could be expensive (the price came down as guns became more common, due to wider spread and large scale manufacture of saltpetre).
Early guns fired bullets as fairly low velocities, which could be stopped by crossbow-proof armour. At this stage, guns didn't have a decisive advantage over crossbows. In the late 16th century, as muzzle energies climbed, guns became more effective, and could penetrate armour that crossbows could not, and guns then proceeded to push both crossbows and armour off the battlefield. Before this, guns were used side-by-side with crossbows.
This improvement was due to the use of corned powder (rolled into larger grains, rather than being left as-made as a fine powder). Guns were also ergonomically improved, with stocks that made firing from the shoulder easier, and trigger mechanisms (first, the serpentine, and then matchlocks and beyond), and slow-match.
why were early guns so quickly able to replace arrow based projectiles
In Europe, that "so quickly" was about 300 years. It took a long time. The replacement of bows by guns as the standard infantry ranged weapon also took a long time in China, again hundreds of years, and the bow persisted for hundreds of years after that as a cavalry weapon (due to the difficulty of loading muskets on horseback in battle).
You might want to look through these answers from the FAQ:
Questions about the rise of guns on the battlefield around the 1300- 1600 era - u/Axon350,
If early guns were so inaccurate and took so long to load, why did they so quickly replace crossbows, archers, and other earlier forms of projectile weaponry? - u/Rittermeister,
Why were primitive firearms used when bows and crossbows were better in every way? - u/Valkine,
If you want clarification on anything or have further questions, feel free to ask! The whole point of this forum is to help people learn. Additionally, history is living, so I would not be surprised if someone popped in with an update to a previously accepted truth.
*EDIT: Fixed links, tagged the linked authors so they can help with any questions.
In addition to all the responses referenced above, I would also like to address two issues.
When early handheld guns in the time when they gained popularity (although they still were not commonplace), i.e. somewhere in the last quarter of 14th century, guns were very simple devices cast from bronze or forged from iron, as evidenced by the Mörkö gun (c. 1380) or guns used by Germans, like this specimen from Tannenberg (c. 1400) or this one from Danzig (c. 1400). As u/wotan_weevil already noticed, the cost and complexity of production of such weapons was relatively low, especially in comparison with the 14th century heavy crossbows with the bows made of wood, sinew and bone laminate and accompanied by the pulling devices, such as the winch or crannequin that were pretty complex mechanisms for their time and required tedious work, especially the latter. Casting a bronze handgun (ger. Handrohr) was no more complex than the creation of a small bell and could have been done in a relatively short time (few hours) using the lost wax method. Iron weapons were more complex, but again, forging the barrels on a mandrel was not that difficult and could have been also accomplished rather quickly in comparison to a manufacturing process of a heavy crossbow.
Now, the gunpowder weapons had one important advantage over the neuroballistic weapons such as bows and crossbows. They were very versatile and had far greater potential for improvement. By the late 14th century, the capabilities of crossbows and especially bows were closely reaching the limit of human capabilities in the case of the former and technological limitations in the case of latter. At the same time, even the most primitive gunpowder had a power rivaling that of the powerful bows and crossbows, with a lot of possibilities of improvement. Furthermore, even though the handheld blackpowder weapons could have been still outmatched by their neuroballistic counterparts, by the beginning of the 15th century it became obvious that they scale very well and the usefulness of the artillery is extremely high what led to constant improvement in that area (types of ammunition, method of construction, propellant formulas etc.) that could have also been later applied to the smaller weapons even if the latter were not developed as intensively.
Speaking of versatility, medieval engineers have shown a good deal of ingenuity when developing gunpowder weapons and they were obviously aware of their potential. As the guns were essentially a small tube filled with gunpowder, it meant that they could have been easily merged into larger assemblies, giving the user a possibility to fire several shots in few seconds, something that archer or a crossbowman equipped with an comparably powerful weapon had basically no chance to do. The multi-barrel Chinese pole cannons from the Ming dynasty period are the best known examples, with three-barrel 'san yan chong' being the most popular, although weapons sporting 6 or 9 barrels also existed. Although similar weapons were used also in Europe as early as late 14th century, as evidenced by this specimen of unknown origin dated 1370s, now exhibited in the Bernese Historical Museum. Such solutions were soon abandoned in favour of simple, single-barrel weapons (but the idea survived in artillery in the form of ribaldequins and other multi-barrel weapons), although their presence shows that people were actively testing various concepts of the new, promising form of weapon, realizing its unquestionable potential.
EDIT: Corrected few typos.