Magento2: [InvalidArgumentException] There are no commands defined in the "setup" namespace.

Created on 20 Apr 2017  路  15Comments  路  Source: magento/magento2


Preconditions

  1. Magento version 2.1(.5)

Steps to reproduce

  1. bin/magento enable:module [moduleName]
  2. bin/magento setup:upgrade

Expected result

  1. upgrade is successfully run

Actual result

  1. [InvalidArgumentException] There are no commands defined in the "setup" namespace.
  2. the "di" folder is empty

quick fix

  1. bin/magento enable:module [moduleName]
  2. bin/magento setup:di:compile
  3. bin/magento setup:upgrade
Cannot Reproduce Clear Description Format is valid

Most helpful comment

You can just run bin/magento list to get a readable error message.

All 15 comments

Either the process should be changed or at least the info message:

To make sure that the enabled modules are properly registered, run 'setup:upgrade'.
Cache cleared successfully.
Generated classes cleared successfully. Please run the 'setup:di:compile' command to generate classes.
Info: Some modules might require static view files to be cleared. To do this, run 'module:enable' with the --clear-static-content option to clear them.

This info makes you think you can just run 'setup:upgrade' when you actually have to run 'setup:di:compile' first.

Although this is temporal-coupling problem between CLI commands, I would also like to point out to the most infuriating and non-intuitive error message in all M2: [InvalidArgumentException] There are no commands defined in the "<NS>" namespace.

Somewhere, an exception happened, but it's hidden by a poor try/catch logic, so you never get to see it. You see that totally unrelated message instead.

@adragus-inviqa, I agree.

It would be much more convenient to leave CLI exceptions uncaught so we can get a full stacktrace and see what went wrong. CLI developers literally have nothing to work with when exceptions are caught this way.

An odd workaround: If your CLI issues are in class constructors/dependency-injection, running magento setup:upgrade will give you a more detailed error message. I don't know why.

You can just run bin/magento list to get a readable error message.

@steros, thanks! setup:upgrade didn't seem like a "good bodge".

Do you find list convenient, or would you still prefer better CLI exception handling?

I was surprised to find out list returns a different message which is actually useful.
All commands should do that.

tryin install magento2 and having first that issue with "There are no commands defined in the 'setup' namespace.

and then i catch the exception with list and get: The --base-url option does not exist. when i麓m erasing the option it is taking the next option as failure.

@Wollhaar this is a different problem, please open a new ticket. Although I suppose this is not a bug but a user error.

@steros, thank you for your report.
We were not able to reproduce this issue by following the steps you provided. If you'd like to update it, please reopen the issue.

@magento-engcom-team I was able to reproduce the same error by accidentally creating a circular reference in my module.xml file. Please improve the exception messages to include more detail. Maybe a --verbose option to show the full stack trace?

Magento version: 2.1.7

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
     <module name="CustomVendor_MyModule" setup_version="1.0.0">
     <sequence>
            <module name="CustomVendor_MyModule"/>
      </sequence>
    </module>
</config>

I can confirm that I had exactly the same issue mentioned here in Magento 2.1.8 . It has to do with a circular redirect in the module.xml file. There should be some kind of circular redirect error to help mitigate this development issue. It was not easy to figure out.

In my case It was problem in registration.php file where i register custom module.
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'HelloWorld',
__DIR__
);

I just comment that code and it is working good for me.Thank you.

It's not about the problem that's causing this but the message that you get that's misleading.

I run bin/magento list to get a readable error message. I found that module.xml contains non UTF-8 chars. It work well after I delete those chars.

@magento-engcom-team your team promised to improve developer experience, here's a good chance to do it
why do you keep ignoring developers?

Was this page helpful?
0 / 5 - 0 ratings