Police officer Mukhtiar Singh said 15 other people were injured in the blast in Batala, a town in Punjab state about 460 kilometers (285 miles) north of New Delhi.
Singh said rescue work is continuing at the site.
Deepak Bhatia, a state government administrator, said the cause of the explosion was being investigated.
The building caught fire after the blast, he said.
Television images showed a brick-lined building that had completely collapsed from the force of the explosion.
News18 television news channel quoted opposition Akali Dal party leader Bikram Singh Mathijia as saying that it was an illegal factory that had existed for years without a licence in a residential area.
Residents complained that authorities had failed to take any action against the factory. An earlier explosion there in 2017 killed one person, according to the news channel.
Fireworks manufacturing is a big business in India, with firecrackers often used in festivals and weddings.
Many illegal factories produce firecrackers that are cheaper to buy than legally made ones.