TO UNDERSTAND South Korea’s transformation into an export powerhouse, climb up to the observatory on Yeompo mountain overlooking the city of Ulsan. To the north, on the left bank of the Tae-Hwa river, stands Hyundai’s vast carworks and a shimmering shoal of new vehicles. To the west, across the river, chemical works lazily puff out white plumes. To the south and east, around the estuary, half-built metal hulls litter Hyundai’s shipyards.

A giant red gantry crane stands out. Bought for $1 in 2002 from the fading Kockums shipyard in Sweden, it is known as the “Tears of Malmö”. These days, the people of Ulsan wonder whether they, too, will soon be crying. Just as South Korean competition sent much of European shipbuilding into bankruptcy, China is now threatening to do much the same to South Korea’s industry.

A decade ago South Korea had been the biggest of the “big three” shipbuilding powers, along with China and Japan, that together account for about 90% of global ship production (see chart). Today its order-book is barely half the size of China’s.

The agony of the shipyards, the country’s biggest exporters after its semiconductor and car industries, feeds South Korea’s disquiet about China. It had until recently been seen as a lucrative export market, buying everything from cosmetics to K-pop. These days China is increasingly regarded as a dangerous competitor. A year-long Chinese boycott of South Korean goods, provoked by the deployment of an American missile-defence system, more or less ended in October. But it deepened the sense that China poses a grievous threat to South Korea’s economic model. The crisis in shipbuilding is instructive. South Korean yards were hit by a global slump, caused first by the financial crisis of 2007-08 and the fall in world trade. A second blow stemmed from shipping firms’ ill-considered binge on huge container vessels in 2011, which led to a collapse in freight rates. A third was the fall in oil prices, which dented orders for oil rigs. This has undone the happy middle position that South Korean shipmakers thought they had found, beating Japanese rivals on cost and Chinese ones on quality. Suddenly, they are being squeezed in what Park Chong-hoon of Standard Chartered Bank in Seoul calls “a nutcracker”. On one side, he says, China “is picking up technologically faster than we expected”; on the other, Japan has gained competitiveness owing to the weaker yen while South Korea is burdened by the strong won. At Hyundai Heavy Industries, the largest South Korean shipbuilder, officials note that orders are down from the usual 60-80 vessels and rigs a year to about 20 in 2016. Although they picked up last year, long production schedules mean that the yard will be in the doldrums for at least another year. “Container ships used to be our main work,” notes a spokesman. “This year we have barely any orders for them.” Hyundai was stunned in August when it lost a French tender to build nine ultra-large container vessels, each carrying more than 20,000 standard 20-foot containers, to Chinese rivals.

Thousands of workers have been placed on part-time rosters, if not laid off altogether. Subcontractors are being squeezed. Some laid-off workers have set up local restaurants, only to go bust within months because of a lack of customers. Others have gone back to their families in farming villages.

President Moon Jae-in, declaring that South Korea “cannot give up” on being a global shipbuilding leader, set out a plan in January to support the industry. This included ordering icebreakers, patrol vessels and offshore wind farms. His push to boost the minimum wage by 16.4% this year elicits little more than passing interest among workers; they worry whether they will have jobs at all.

Everyone talks of modernising shipbuilding by extensive use of digital technology. The trouble is that China is also seeking to adopt advanced manufacturing methods. A report last year from the Mercator Institute for China Studies, a German think-tank, identified South Korea as the country most exposed to the resulting Chinese competition.

To judge from the macroeconomic figures alone, South Korea still seems to be prospering. Last year growth passed 3%, goods exports were up 13% (despite the Chinese boycott) and the unemployment rate was 3.7%. But Mr Park notes that there is much nervousness within individual industries. “I am more worried than optimistic,” he says.

Carmaking, he thinks, could soon feel the force of Chinese competition. Car exports to China were in decline even before the boycott as the quality of Chinese cars improved and South Korean brands failed to match the appeal of Japanese and European ones. Moreover, South Korea risks being left behind by China’s effort to shift to electric cars, and even more so by the advent of driverless vehicles. Chemicals, another mainstay of South Korea’s economy, look exposed. Semiconductors are most resilient, for now.

It is sometimes said that South Korea’s economic interests lie in partnership with China, but its security depends on its military alliance with America. Under the disgraced former president, Park Geun-hye, South Korea sought to move closer to China, signing a free-trade agreement in 2015. Mr Moon, her successor, has extracted a promise to extend the deal to services and investment, but that seems a long way off.

The two sides are still bruised by the missile-defence debacle. South Korea and America insisted that the sole target was North Korea, whose aggressive pursuit of nuclear missiles left them no choice. China argued that the radar could be used against it as well. Government insiders say they are aware of the limits of the relationship with China, and know that South Korean firms struggle to compete with Chinese industries that are financed and directed by the state. Many South Korean firms are redirecting investments, towards America in large part.

This would thus seem to be a propitious moment for South Korea to align both security and economic interests towards America. But Donald Trump often seems to be pushing it back into China’s arms. He has demanded a renegotiation of America’s free-trade deal with South Korea. He has also slapped punitive tariffs of up to 50% on imports of South Korean washing machines (along with tariffs on solar panels from China). South Korea has asked the World Trade Organisation’s permission to retaliate with penalties of its own.

South Korea worries even more about Mr Trump’s belligerence towards North Korea and his talk of pre-emptive military strikes to destroy its nuclear weapons. If there is one thing that brings China and South Korea closer together, officials whisper in Seoul, it is their dread of a war started by America.