1

I created a module.xml under the app/code/my/module/etc folder.

<?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="my_module" setup_version="1.0.0" />
</config>

Than I tried to enable the module with following command

php -f bin/magento module:enable --clear-static-content my_module

And get this error:

Unknown module(s): 'my_module'

Why don't Magento find the module?


Here is the error after executing the flush command:

[InvalidArgumentException]
There are no commands defined in the "cache" namespace.


Now here is the error:

Additionally to the xml syntax in the module.xml I added comments. These comments caused the error.

3 Answers 3

6

Well you have to first clear the cache by running the following command.

php -f bin/magento cache:clean

or

php -f bin/magento cache:flush

Then as you executed cache commands, it is possible that permissions are revoked on many files which are being executed during module enabling and disabling.

So if you're on linux(Ubuntu/Debian) then provide full permissions to your root magento directory as below:

cd /path/to/magento2
sudo chmod -R 777 .

Then, provided you've already created 'registration.php' file in your module directory(magento2root/app/code/My/Module/) like below,

<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    'my_module',
    __DIR__
);

run the module enable command you mentioned in your question.

It is not mandatory to have 'composer.json' for module enable-disable, composer.json is needed for git-based tasks(commit module code/update module code etc.) if you have active repo of your site at Github.

6
  • I've tried everything with the registration.php and composer.json, but nothing works. I also get the following error if I try to execute the flush command: php -f bin/magento cache:flush I've got the following error: There are no commands defined in the "cache" namespace.
    – ClassMP
    Dec 16, 2015 at 16:34
  • That's because there is some syntax error or exception in your current module(the module you're trying to register) or any other module you've installed previously. I got this error many times and everytime it was some syntax issue(any variable/object used without declaration or extending unavailable/invalid class), please check all your code (in app/code dir)thoroughly for any kind of syntax or typos. Are you using Magento 2.0.0 stable release ?
    – Vicky Dev
    Dec 16, 2015 at 16:46
  • Yes I Do. I downloaded it from the magento page.
    – ClassMP
    Dec 16, 2015 at 16:55
  • Well then do check all the installed modules of app/code dir for any syntax issues. Once those are resolved then the steps in my answer should work all-right. They are working for me already.
    – Vicky Dev
    Dec 16, 2015 at 17:02
  • Ok, also I see from your screenshot, you're using Windows with Xampp installed, right ? Well then you have to provide full permission to magento2root dir for user "www-data", permissions and syntax-error-free code are necessary for the magento2 commands to run successfully.
    – Vicky Dev
    Dec 16, 2015 at 17:06
1

Have you created a registration.php file in /app/code/my/module ?

If not, do, and add this to it:

<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/

\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    'my_module',
    __DIR__
);

you'll also need a composer.json in the same directory:

{
"name": "my/module",
"description": "my module for Magento 2",
"require": {
    "php": "~5.5.0|~5.6.0"
},
"type": "magento2-module",
"version": "1.0.0",
"license": [
    "OSL-3.0",
    "AFL-3.0"
],
"autoload": {
    "files": [ "registration.php" ],
    "psr-4": {
        "my\\module\\": ""
    }
}
}

Then re-run:

php bin/magento module:enable --clear-static-content my_module
1
  • Yes I did. See comment below.
    – ClassMP
    Dec 16, 2015 at 16:36
0

once you created your module you need to deploy,

run following command \bin\magento setup:static-content:deploy OR open app/etc folder add 'my_module' => 1 in config.xml, and clear the cache.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.