The Model S was an expensive car with a bad reputation for quality. Then in 2017 they introduced the Model 3 and their "Alien Dreadnought" automation. That significantly delayed mass production of the Model 3 and almost bankrupted the company.
Tesla turned things around by building a factory in Shanghai, and learning how to build a car from the Chinese. They then basically copied the Shanghai factory to Germany.