HOW quickly the mood can turn. Barely a year ago Indonesia was the toast of emerging-market investors. The country revelled in the world’s demand for its vast reserves of coal, oil and other resources, and celebrated with a consumer boom: economic growth clipped along at over 6%. Politics was stable, macroeconomic policy sound. Foreign investors were scrabbling to get into a market of 240m people and apparently boundless potential.

Today things look different. Investors are spooked by economic concerns. Growth is slowing, even as inflation heads up. In the second quarter GDP growth slowed to 5.8%, and it will certainly undershoot the government’s target of 6.3% for the year. Inflation, meanwhile, rose to 8.6% in July. Financial markets have taken a battering. After falling by 7.7% over three days, the benchmark stockmarket index is down by a fifth from its record high in May. The rupiah, a dismal regional performer of late, is at its lowest level against the dollar in four years. Foreigners have sold $1.4 billion of government bonds since June.

After a good run, many Indonesians have been caught out by the sudden turn. Yet bewilderment has not turned to panic. Some think that Indonesia is merely being caught in a more general sell-off of Asian shares and currencies, prompted by fears that America’s Federal Reserve will soon end its policy of ultra-cheap money. Economists also argue that much of the recent bad news about the economy is just temporary. For instance, inflation has jumped mainly because the recent removal of fuel subsidies led to a one-off rise in the cost of petrol. Inflation, they say, should soon fall back to 5%.

Nonetheless, Indonesia is being hit as hard as anywhere in Asia. For all that this week’s sell-off reflected concerns about the Fed’s ending of quantitative easing, it was also a reaction to a deteriorating current account. After 14 years of surplus, the current-account balance swung to a deficit of 2.7% of GDP in 2012. In the latest three months of data, the gap widened to 4.4% of GDP, it was announced on August 16th. And this is only one symptom of wider structural problems which the country failed to tackle when it was enjoying an economic tailwind.

The government of President Susilo Bambang Yudhoyono, who is serving his second term, had promised to grapple with the problems of Indonesia’s awful infrastructure, foot-dragging bureaucrats and rampant corruption. Yet even by Mr Yudhoyono’s admission, it has failed to do so. Scandals have multiplied. The latest is at the nation’s oil-and-gas regulator (see article). When the going was good, such negligence seemed not to matter. Now, with a fall in commodity prices and the prospect of an end to cheap money, Indonesia’s failure to revamp its economy is laid bare. Investors have little confidence that the country can find new sources of growth. Even before this week’s financial jitters, Indonesia had slid down various rankings of investor confidence.

Also spooking investors is a recent increase in economic nationalism intended to disadvantage foreigners. In the substantial mining industry, the government for some years has insisted that foreign companies refine or process in Indonesia the minerals, such as copper, which they extract, rather than simply shipping ores and concentrates abroad. This stipulation was made in the hope of creating more Indonesian jobs and investment.

Yet such laws have also come with heavy restrictions on the share of local businesses that foreigners may own. The trend is also apparent in plenty of other industries, including banking, where until not long ago Indonesia ran one of the most open regimes in the world. Now, regulations stipulate that new investors may not initially buy more than 40% of a local bank. With parliamentary and presidential elections next year, policies are likely to get even more restrictive as politicians appeal to voters’ nationalism by bashing foreign capital. As one parliamentarian from the ruling party, Ramadhan Pohan, sums it up, “neoliberalism is a stigma and when you support this, you are finished.”

In good times, Indonesia might have been able to afford the luxury of such posturing. But those times, all of a sudden, are over. Now that profit margins are coming under pressure—for example, from the government’s requirement that miners build local smelters—many foreign investors will begin to look elsewhere, just at the moment when Indonesia might need them most.