There were weapons, powerful weapons at that, but they depended heavily on artisanal production even if certain groups managed to reach manufacturing scale.
Also, Middle Earth is still licking wounds from the great wars with Melkor, which took away most of the advanced regions, and what Gondor and Arnor tried to rebuild got heavily whacked down by wars.
Random subsistence farmers spread across small hamlets do not make for industrial base, whereas Saruman and Sauron could use force to speedrun the development to provide resources for their forces (as both had knowledge of how to do it, even if we only take into account their experiences during wars of Beleriand - meanwhile the wizards other than Saruman stick to their oath of non-interference)
The remaining higher technology groups either lost the capability (Gondor), were destroyed (Arnor), are fighting constant war with Orcs with occasional dragon making problems that prevents building up proper industry (Dwarves), or are depopulated depressed groups that while not hoarding, do not interact with others anymore much and mostly use what remains of their industrial base to facilitate the last days of their race (Elves outside of Mirkwood - those in turn are trying but don't have much to build upon since Moria got overrun and they lost their main trading partner for technology).
The rest is down to subsistence farming levels without base of previous knowledge to rebuild or at least inspire.
Probably the most honest reason to not have guns in Middle-Earth is that only stupid orcs, not the elves and dwarves who could easily develop them as school projects, would be interested in such tasteless weapons.