In the Star Trek world, I think the transporter and the replicator are the same technology just applied differently. When transporting goes wrong, they mention things like “pattern buffers”, where (presumably) information about how to reconstruct the person’s matter is held until all info arrives. I suspect you hold on to the pattern buffers for things you want to replicate. Unanswered by this… where does the matter come from? Maybe just reconstituted energy from the engines.