France's ruling coalition of Socialists and Communists suffered heavy losses today in politically important municipal elections seen by the opposition as a nationwide referendum on the policies of President Francois Mitterrand.

Early results and computer projections from 221 large towns and cities indicated that the left would lose much if not all of the ground it gained at the last municipal elections in 1977. Final results will not be known until next Sunday when runoff elections are held in cities where neither side won absolute majorities, but jubilant opposition leaders already were claiming victory.

The losses represent a major setback for Mitterrand, who is less than two years into his seven-year mandate. They are likely to have a major impact on the political geography of France with possibly as much as a quarter of the major towns changing hands.

In its campaign, the opposition concentrated its fire on the government's poor economic record, which includes a steadily worsening foreign trade deficit, high unemployment and two devaluations of the franc. Socialist attempts to reassure the voters appeared to have some initial success but were undermined a week ago by the announcement of damaging economic data on inflation and the balance of trade.

Computer estimates by the French news service Agence France-Presse indicated that, in the big cities where the main political battles are being fought, the right would win around 51.5 percent of the vote while 46.5 percent would go to the left with the remainder to fringe parties. This compares to a vote of 50.8 percent for the left in the same cities in 1977 and 46.3 percent for the right.

The results were described by Jacques Chirac, the head of the neo-Gaullist party and the victorious mayor of Paris, as "an unequivocal warning to the government." Lionel Jospin, the Socialist Party secretary who was badly defeated in his own district of Paris, acknowledged that the right had made gains but appealed to his supporters to mobilize themselves for the second round.

The swing to the right could cause delicate political problems at a time when the Socialist government is committed to devolving more power to the provinces and to reforming what traditionally has been a highly centralized state bureaucracy.

A major upset for the Socialists was the loss of Grenoble in southeast France, a city that had been in their hands for 18 years and was regarded as something of a showcase for good government. They also lost Brest in the northwest, Roubaix in the north, Nantes in the west and Avignon in the south.

The Communists also fared badly, losing control of Reims, where they were challenged not only by the right but also by their Socialist coalition partners. In most other towns, voters were faced with a straight choice between a unified list of candidates from the left and one from the right.

Several prominent Socialist leaders faced strong challenges from the right in their home towns. Interior Minister Gaston Defferre saw his vote slump in Marseilles, a port city that he has governed as mayor for 30 years. But it appeared likely that he would win in the second round.

Prime Minister Pierre Mauroy, who put his personal prestige at stake by his energetic campaigning, lost ground in the industrial city of Lille where he is running as mayor but seemed likely to be reelected. He could be among the first casualties if Mitterrand decides later this year that someone must be sacrificed as a scapegoat for the government's unpopularity.

Of 35 government ministers standing for election as mayors, at least six have already lost--with a dozen others facing difficult runoffs in the second round.

In 1977, the Socialists and Communists together won 154 cities, an increase of 61 towns they took from the right. The vote was interpreted as a personal defeat for the then president, Valery Giscard d'Estaing, who was voted out of office four years later.

Socialist and Communist leaders attempted to put some of the blame for today's defeat on the failure of their supporters to come to the polls. At a press conference in Marseilles, Defferre said that "the right succeeded in mobilizing all their supporters on the first round but we didn't manage to mobilize ours."

Independent political analysts, however, doubted whether this was a determining factor since the turnout was about 80 percent, a record for municipal elections.

Describing the vote as "a great success for the opposition," the former prime minister under Giscard, Raymond Barre, said it proved that the left no longer had a majority in France.

The size of the opposition gains came as a surprise to the pollsters who had predicted a much more modest victory for the right. But opinion polls are banned in France in the final week before the election.

French commentators already were predicting that the setback for the government, combined with the victory of the Christian Democrats in West Germany, would put new pressure on the franc. Officials have denied that a new devaluation is planned, but there is speculation that new austerity measures are under consideration.