Needs[] returns error: Context "MyPackage" was not created when Needs was evaluated

Needs[] returns: Context “MyPackage” was not created when Needs was evaluated.

I have added the path to the package file and checked that the path is actually correct and present.

The package looks like this:

BeginPackage["MyPackage`"]

.........

Begin["`Private`"]

<Function definitions> 

End[]

EndPackage[]

Any idea?

Have you tried using a get (<< "/Users/documentation/Desktop/MyPackage.wl") statement instead? I believe get parses the directories differently which may be it. Or perhaps try and use the full path to your file if you’re not already (e.g. C:/…). The actual package file looks fine though.
Maybe if the former don’t work/you’ve already tried them, you could share the code that’s loading the package? Thanks :).

Yes, I tried “Get” and also included the path in the call (both for “Needs” and for “Get”), just in case. Moreover, I also tried to copy the .wl file to a folder already present in “Path.” Still, the same problem.

Just to check, that your code for loading it definitely has a backquote on the end?
As in <<MyPackage` or otherwise Needs[MyPackage`]`. It’s worth trying both, and also with the path done in different ways as mentioned.
If not, I’ll try and replicate the problem in a minute.

Best would be if you could attach the .wl file of the package (or a simplified or skeleton version of it) . Then it is easier to help you troubleshoot.