Please provide sources if possible
Although this is popularly claimed, it isn't quite true. As the US Office of the Historian (part of the Department of State) claims, France was the first to recognize America on February 6, 1778. The same source shows us that the United States and Morocco did not sign a formal treaty of friendship until 1786 and, although a consular presence was quickly established, permanent relations only began in 1905.
So where does this confusion come from?
There is a lot of misinformation about early relations with the United States. If you read at all the Wikipedia page on Diplomatic Missions of the United States it would claim that the Netherlands were actually the first to recognize America. However, going back to the Office of the Historian, The Netherlands' recognition of America in 1782 made them the second nation, behind France, to do so. Part of this confusion may have come from the fact that The Netherlands, on November 16, 1776, were allegedly the first to salute an American Ship as if it came from a friendly, independent country.
According to the Moroccan Country Study Guide, under "US-Moroccan Relations", Morocco was the first to seek diplomatic relations in 1777. However, formal relations were not created until the Treaty of Peace and Friendship in 1786. This treaty did make Morocco the first Muslim-majority nation to recognize the United States, and this treaty is often used as proof to argue that the United States was not meant to be a Christian nation, as Article 11 states:
As the government of the United States of America is not in any sense founded on the Christian Religion,-as it has in itself no character of enmity against the laws, religion or tranquility of Musselmen,-and as the said States never have entered into any war or act of hostility against any Mehomitan nation, it is declared by the parties that no pretext arising from religious opinions shall ever produce an interruption of the harmony existing between the two countries.
Nevertheless, one can see how this may get confusing. The Treaty of Peace and Friendship is the longest unbroken treaty in US History. Additionally, Morocco does hold the oldest US diplomatic property (as in property owned by the United States. John Adams' house in the Netherlands which later became The Hague was privately owned). But was Morocco the first to recognize America? It can be seen that although their recognition came early, formal relations with them were not the first.