I’m willing to believe that for the most part, the world Star Trek inhabits is postscarcity - the widespread replicator technology leads me to believe that with easy access to energy and organic material, everyone can be fed and clothed with a minimum of expenditure, and with access to FTL travel and terraforming tools, land scarcity is no longer an issue either.
The economy is just a tool for the distribution of goods, services and land; it becomes unnecessary if everything necessary to sustain life (and probably quite a few luxuries and leisures) is readily available as it’s needed.
I can’t remember what series it is, but one of the newer series has a scene where someone is asking why the federation won’t give them replicator tech. And the federation dude basically lays out how replicator tech before society is ready leads to oppression not liberation. That humanity only got replicator tech after they already came together and threw off the old ways. Replicator tech didn’t lead to socialism for them. Socialism lead to replicator tech.
While the technology of star trek definitely plays a role in terms of it being anti capitalist, it’s not just the tech. If today somebody invented a replicator, it wouldn’t be a full decade before its use would be locked behind a dozen different tiered paywalls on top of the instalation cost, and then eventually it going through enshitification.
The societal values and culture in star trek values life, far, far above weath and profit to the point that such concepts are basically alien. And that has to be the first step for post scarcity tech to actually be used for the purpose of post scarcity.