WASHINGTON – The U.S. posted solid gains in exports in May, a positive sign for the economy. And while imports grew even faster, some economists saw that as a hopeful sign because it suggests companies are betting that consumers will spend more in coming months.

The surging value of imports caused the trade deficit to reach an 18-month peak. It rose 4.8 percent to $42.3 billion, the largest deficit since November 2008, the Commerce Department said Tuesday.

U.S. exports of goods and services rose 2.4 percent to $152.3 billion. It was the largest monthly total since September 2008, the month the financial crisis struck with force. Leading the strength in exports were heavy machinery, medical equipment, power generators and commercial planes.

Imports grew even faster. They rose 2.9 percent to $194.5 billion. That gain reflected higher demand for foreign-made cars and consumer goods such as clothing, furniture and electronic appliances. The surge came even though the value of oil imports sank 9.1 percent to $27.6 billion as both the price and the volume of oil shipments declined.

Economists said the widening trade deficit would likely reduce overall growth, as measured by the gross domestic product, in the April-June quarter. But in the long run, analysts held out hope that the gains in both exports and imports point to higher business investment and consumer spending.

“This will certainly prove supportive to economic growth in the months to come,” Martin Schwerdtfeger, an economist at TD Economics, wrote in a research note.

Through May, the U.S. trade deficit is running at an annual rate of about $475 billion, up more than 25 percent from a $374.9 billion deficit for all of 2009. That had been the lowest annual trade gap since 2001, another year when the country was in recession.

The wider May deficit was a surprise to analysts, who had expected the gap to decline slightly because of the fall in oil imports. The larger trade gap caused some economists to trim their forecasts for overall growth in the April-June quarter, though many said they expected less of a drag in coming quarters.

GDP is the value of all goods and services produced in the United States. U.S. exports add to GDP because the products are made in the United States and shipped abroad. contrast, imports reduce GDP because the government considers imports a substitute for what could have been produced in the United States.

Many economists saw the rise in imports as a sign of increased business optimism about the future. They said U.S. companies were importing more goods in anticipation of higher consumer spending later in the year.

“The strong increases in both export and import volumes are far more important as a sign of continued growth at home and abroad than the widening trade gap,” economists at forecasting firm RDQ Economics wrote in a research note. “It seems to us that the expansion of world trade has a robust momentum.”

American manufacturing has been a standout performer during the recovery, benefiting from a global rebound. Those gains risk being diminished by the European debt crisis, which has slowed growth in Europe and raised the value of the dollar 14 percent this year versus the euro. A stronger dollar against the euro makes U.S. goods costlier and less competitive in Europe.