Tesla and SpaceX aren't worth that much for much the same reasons you've outlined - they have massive capex requirements, high employee overhead and retention costs, and really real technology risk (it's literally rocket science).
If I sell you a Book for a million dollars, I make 1 million dollars. If I sell a million books for a dollar each, I make a million dollars. My Company is worth a million dollars. It makes no difference to the quality or what i am selling.