I'm not sure why you don't think space is commercially viable right now, companies and governments are paying a lot of money to have things delivered to orbit. SpaceX is making money with every launch otherwise they would have gone bust years ago. If you mean there's no market for human spaceflight, well there wasn't a market for passenger railroad travel for a long time either. You need to build the railways before people can make practical use of them. Back when most railways only extended for 1 or 2 km it was pretty hard to imagine getting paying passengers. You have to build something that connects to places people want to go before they'll pay to ride it.
With spaceflight we're currently in the shorthaul stage, all the profit is in delivering cargo to LEO. The cost is coming down and people are finding more uses for cheap satellites. The rockets already have their use case, they move people and cargo the same as a railroad, it's what we do with that capability that we need to get creative with and as we continue to build out capability and lower cost there will be more and more uses for space. The main reason I compare it to railroads is that it is a type of infrastructure that makes new things possible and there's always a profit to be made in a frontier as long as you're daring enough to take it.
Steam engines were originally used for pumping water, but there was an obvious huge demand for locomotives to move freight by land once they could be made cheaper or better than draft animals.
I’m sure there exist some commercial uses for space flight, but it really doesn’t seem all that similar to railroads in terms of obvious market demand or effect on the economy.