Field formatter module throws cannot declare class error
Here are some pointers that might help:


Run drush cr to clear cache and see if the error persists.
Enable error backtraces from the Config &gt; Development &gt; Logging &amp; Errors page to see if you get more info in the error message about where the class is being redeclared.
Search your project for the name MyFormatter and see if you find anything besides the MyFormatter.php file you've mentioned.
File, directory and class names are case-sensitive – in what you've shared, they seem to be correctly named.
Make sure you're not manually using require or include anywhere to include this file.


Probably, not applicable in your case.