How to fix the «There are no commands defined» failure while executing a console command?

[2017-11-15] Struggling with this problem? Order my resolution service!

In my case the source of the problem was absense of an extension’s etc/module.xml file.

A similar problem: «An abstract factory could not create an instance of».

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

<module name='TwitterTimeline' setup_version='2.0.0'/>

instead of

<module name='Dfe_TwitterTimeline' setup_version='2.0.0'/>

it will lead to the same There are no commands defined error.

1 Like

See also:

  • All There are no commands defined issues in the tracker.
  • All There are no commands defined questions on

thanks dmitry!!! it helped me lot.

It not working for me, when i am trying to run indexer like
php bin/magento indexer:reindex

then its shows

There are no commands defined in the “indexer” namespace.

and also tried
sudo php bin/magento indexer:reindex

Then its shows
Content-type: text/html; charset=UTF-8
bin/magento must be run as a CLI application

You can remove your extensions one-by-one to detect which your extension is wrong.

I recommend to set a breakpoint here:

As you can see, the exception’s message is «The file “/composer.json” doesn’t exist» in my case.

You can also set breakpoints here:

I have been faced with same issue. Your solution helped. Thank you for sharing!

Today I have fixed a similar issue in the mage2pro/core package with Magento Marketplace:

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.

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 :slight_smile:

How to fix «There are no commands defined in the “setup:cron” namespace» onbin/magento setup:cron:run in Magento ≥ 2.3.7?