The blast occurred last night in a rural area of central Puebla state, Diodoro Carrasco, a senior official in the state government, told radio station Cinco Radio.
News reports said 11 of the fatalities were minors but the government did not immediately confirm this.
The explosion came during preparations for a religious festival on May 15, the Puebla state government said.
There are people who live in the building where the fireworks were being stored, it said.
The blast was set off by a rocket that was fired from outside the building and struck the stored pyrotechnic material, the government said.