Washington imposed penalty tariffs on Chinese goods and Beijing retaliated by raising duties on imports of American products including electric cars.

China is the biggest global electric vehicle market and Tesla’s second-largest after the US.

California-based Tesla joins global firms including General Motors, Volkswagen and Nissan in pouring billions of dollars into manufacturing electric vehicles in China.

Local production would eliminate risks from tariffs and other import controls. It would help Tesla develop parts suppliers to support after-service and make its vehicles more appealing to mainstream Chinese buyers.

Elon Musk (Marcio Jose Sanchez/AP)

The move is “an important milestone for what will be our next advanced, sustainably developed manufacturing site”, Tesla’s vice president of worldwide sales, Robin Ren, said.

Shanghai is a centre of China’s motor industry and home to state-owned Shanghai Automotive Industries, the main local manufacturer for GM and VW.

Tesla has said production in Shanghai will begin two to three years after construction of the factory begins and eventually increase to 500,000 vehicles annually.

Tesla has yet to say how it will pay for the factory. The company has yet to give a price tag but the Shanghai government said it would be the biggest foreign investment to date.

Analysts expect Tesla to report a loss of about 200 million dollars (£152 million) for the three months ending on September 30 after the previous quarter’s 742.7 million dollar (£565 million) loss.

Chief executive Elon Musk said in a September 30 letter to US regulators that the company was “very close to achieving profitability”.

Tesla’s estimated sales in China of under 15,000 vehicles in 2017 gave it a market share of less than 3%.

The company faces competition from Chinese brands including BYD Auto and BAIC Group that already sell tens of thousands of hybrid and pure-electric vehicles annually.

Until now, foreign car makers that wanted to manufacture in China were required to work through state-owned partners. Foreign brands baulked at bringing electric vehicle technology into China to avoid having to share it with potential future competitors.

The first of the new electric models being developed by global firms to hit the market, Nissan’s Sylphy Zero Emission, began rolling off a production line in southern China in August.

Lower-priced electric models from GM, VW and other brands are due to hit the market this year, well before Tesla is up and running in Shanghai.