Another cause of the There are no commands defined message could be an error in etc/module.xml file.
For example, if you made a mistake in the module’s name and write
If you have just moved a website to anther server (e.g., localhost) and is starting to get the «There are no commands defined» error, then the most probable reason for it is outdated database connetion credentials in the app/etc/env.php file.
Hi
in my case i setup magento on local and due to high memory usage i turned off xampp and when i try to use this command i was getting same error
“There are no commands defined in the “indexer” namespace.”
So it means you need to check if magento is connected to database and also apache or nginix is running
hope it helps