We know the replicator can create matter from thin air. This is tried and tested technology even in the TNG era.
The replicator is not a matter creator, it's a matter re-arranger, capable of reordering something into something else. It's not some magic hole where food and parts come from, the ships have onboard matter stores. It's basically an offshoot of transporter tech.