Image copyright Getty Images Image caption Mr Trump insisted leaving the TPP was good for American workers

Free trade and globalisation had a bad 2016, but it looks like 2017 could be even worse.

For decades there has been a consensus that globalisation brought more jobs, higher wages and lower prices - not just for richer countries but also for developing and poorer nations.

But there is now a growing movement of anger as people see jobs being taken by machines, old industries disappearing and waves of migration disturbing the established order.

Global trade flows are falling and trade deals are being ripped up.

The new US President Donald Trump has threatened to impose tariffs of up to 45% on Chinese goods, accusing the country of economically "raping" the US.

One of China's fiercest critics, Peter Navarro, has been appointed as a top trade advisor.

Image copyright Getty Images Image caption A Japanese factory's Donald Trump masks are in demand, but the US exit from the TPP agreement will hit trade between the two countries

An executive order pulling out of the 12-nation Trans-Pacific Partnership (TPP) agreement aimed at deepening economic ties between the twelve countries that border the Pacific Ocean was one of Mr Trump's first acts on moving into the White House.

The future of free trade is looking very gloomy.

But what's behind the anger that threatens decades of relative global consensus on globalisation?

US manufacturing's decline

The sense of grievance in the US is clear: the manufacturing sector in the country has seen six million jobs disappear between 1999 and 2011, according to the Bureau of Labor Statistics.

Studies have shown that the decline in the US has been mirrored by gains in China.

Image copyright Getty Images Image caption Automation has helped drive the decline in US manufacturing jobs

But Chinese imports only explain 44% of the decline in employment in manufacturing in the US between 1990 and 2007, according to a report by the Institute for the Study of Labor in Bonn.

Part of the decline has been down to the outsourcing of jobs to other countries but automation and more efficient processes have also taken their toll.

"All countries end up with losers from technological development - whether it is telephone operators or bank tellers," says Gary Hufbauer, a trade expert from the Peterson Institute for International Economics.

"The problem in the US is that we don't do much to help those people who lose out through social security support or job retraining," says Mr Hufbauer.

The anger that flows from this has found a home in the protectionist rhetoric of politicians like Mr Trump.

"There has been no growth in household income during the last decade in Europe, the US and Japan. People are not happy and if you have to blame someone, it is easy to blame foreigners,"' says Mr Hufbauer.

The rise of political opposition to globalisation has coincided with - and contributed to - a period of declining world trade growth since the financial crisis of 2008.

Between 1986 and 2008 world trade grew at an average of 6.5%, according to the World Trade Organization.

Between 2012 and 2015 that rate has slowed to an average of 3.2% and is predicted to expand by just 1.7% in 2016.

That slowdown would make it the longest period of relative trade stagnation since the Second World War.

Since the financial crisis the slowing of the Chinese economy and political and economic stagnation in the eurozone have contributed to this flat-lining of world trade.

At the same time, in an attempt to insulate companies and industries at home, politicians have turned to tariffs and restrictions on imports from other countries.

"Governments worldwide have almost doubled their resort to trade distortions in the last two years," says Prof Simon Evenett, a trade expert at St Gallen University.

"The recent surge in 'beggar-thy-neighbour' activity predates Trump and Brexit, suggesting that populist pressures are likely to exacerbate protectionism," he says.

The flat lining of economic growth has increased pressure on politicians.

"Governments across the world are enacting protectionist policies often masquerading as 'industrial policy," according to Prof Evenett.

He says this often involves offering government subsidies to local companies, introducing import barriers and new '"local" standards for products from abroad.

Yet while protectionism may seem appealing to politicians assailed by angry workers, they often only end up raising prices for consumers.

For example, there was an outcry in 2012 when cheap Chinese tyres flooded into the US market, putting the viability of the domestic producers in question.

President Obama responded with punitive tariffs to get China "to play by the rules".

The protectionist measures were well received in the US, but a study by the Peterson Institute established that the tariffs meant US consumers paid $1.1bn more for their tyres in 2011.

Each job that was saved effectively cost $900,000 with very little of that reaching the pockets of the workers.

Free trade fightback?

With the economic and social benefits of free trade coming increasingly under attack, proponents of globalisation have tried to launch a counterattack.

For example, The World Bank recently published a study of developing countries showing that average incomes for people living in the bottom 40% increased between 2008 and 2013, despite the impact of the financial crisis.

"There is a realisation in rich countries and among rich elites that there are problems with globalisation," says Branko Milanovic, an economist whose work on income inequality has driven much of the debate.

"They realise that for their own political self-preservation they have to tackle them."

But the solutions are not obvious, nor easy to implement.

"Most of the benefits of globalisation have been enjoyed by a relatively small group within each country.

"The question is not whether there are benefits to globalisation - there clearly are. But the question is about who is enjoying those benefits," says Andrew Lang from the London School of Economics.

Part of the anger might dissipate if economic growth was to stop its stubborn flat-lining trajectory, lifting incomes around the world.

Image copyright Getty Images Image caption Many in the US, Europe and Japan have seen no increase in their household income in the past 10 years

"To help solve these problems you need to get the world economy revved up. Governments need to commit to fiscal stimulus to get their economies going again," says Gary Hufbauer.

Branko Milanovic points to the success of previous politicians in turning round seemingly intractably weak economies.

"It's not impossible for politicians to address these issues.

"Thatcher and Reagan managed to effect change in relatively short periods of time - a presidential term of four years should be enough to start making a difference," he says.

But Prof Evenett is pessimistic: "I expect the global plateau in world trade to continue in 2017 and that is before Donald Trump enacts any of the protectionist measures he has threatened."