I've noticed that in history, although Spain and Portugal were right next to Morocco for centuries, they never conquered it yet France did. Come to think of it, Spain hardly had any African territory at all. Why is that?
The conquest of Africa by European powers is often described in terms of a "race" or "scramble" and this is largely accurate. The strongest powers on the European continent were able to dictate the terms of Africa's appropriation to a degree the lesser powers were unable to match. France was the global power of note in the early 18th century, and until ww2 one of the strongest powers on earth. Spain, in its heyday, mostly invested into the americas and not Africa. At the start of the French colonial experience, however, the remaining land was in North Africa, and there was an aggressive effort to conquer this territory.
Morocco borrowed a lot of money from France, to buy weapons to fight some rebels in the Rif. When the King couldn't pay back the money + interest, he allowed France to manage all the kingdom farms until they get their money back.
Portugal did conquered some cities of Morocco, but the whole point of the Portuguese Empire was more based on economics, in market exchanges and not in controlling areas.