Why Tesla Is Investing $5 Billion in a New China Factory, Its First Outside the U.S.

China is the world’s largest market for electric vehicles, and Tesla (TSLA) wants in. Making good on rumors that have swirled for over a year, Bloomberg reports Elon Musk’s company is investing $5 billion in the factory near Shanghai. And Tesla may raise some of the funds in China, according to an insider.

The reasons for Musk’s drive to produce Teslas in China are clear: Doing so offers better access to the domestic market, and it eases the effects of punitive tariffs for its Chinese customers. Tesla cars cost more in China than in the U.S. because of the cost of shipping and the 40% tariffs recently raised in the ongoing U.S.-China trade war.

A Shanghai factory wouldn’t totally free Telsa from the costs associated with importing into China, however. Even if Tesla’s wholly owned factory is in a free-trade zone, it will have to include tariffs in its prices, though it may save on local components, the New York Times reported last year. Only by forming a joint venture with a domestic company — or in the case of special permission from Beijing — would it avoid tariffs.

China has been on Tesla’s radar for a long time. Last month, the company said it hopes to produce 500,000 cars annually in China, and aims to have the Model 3 rolling off local assembly lines by 2020. With a rapidly growing middle class, China is Tesla’s second-biggest market after the United States. Sales of electric cars in China doubled in 2017, surpassing 1 million for the first time.

Tesla is also pursuing a European location for a new gigafactory, which would produce both cars and batteries. Officials in the Netherlands and western Germany have been wooing the carmaker, which would like to avoid import tariffs for its customers in Western Europe.

Currently Tesla only has one factory in Fremont, Calif., to produce all of its vehicles, with the batteries produced outside of Reno, Nev. The company made just 88,000 vehicles in the first half of 2018.

Subscribe to Well Adjusted, our newsletter full of simple strategies to work smarter and live better, from the Fortune Well team. Sign up today.