In Magento2 I've built a simple custom module and want to enable it by CLI:
bin/magento module:enable Vendorname_Modulename
But it is giving me the following error:
Unknown module(s): 'Vendorname_Modulename'
The module and it's files do exist in app/code/Vendorname/Modulename/
Of course I've cleared/disabled caches, cleared generation, Memcache(d) not running…
Best Answer
registration.php
missingApparently my
Vendorname_Modulename
module was missing theregistration.php
. I'm running the latest Magento2 version from GitHub.Every module has to register itself in the
ComponentRegistrar
. A typicalregistration.php
for a module (in the root of your module) could contain:Also see any Magento core component in
app/code/Magento/
or yourvendor/magento/
dirregistration.php
NOT missingIn addition to this, if you DO have a
registration.php
file in your module, but you are still getting this error, this means that yourregistration.php
was not loaded and Magento2 does not know about your module.Your module should be under
app/code/
(where Magento2 will search folders inapp/code/
and find your module'sregistration.php
), but if you have built your module as a Composer package, it will be in Composer'svendor/
dir and you'll need to trick Composer into loading your module'sregistration.php
(Magento doesn't search invendor/
by itself).If you'd check any Magento2 module's
composer.json
invendor/magento/module-*
, you'll see an"autoload"
section which references theregistration.php
file. So Composer will autoload your module'sregistration.php
which will "tell" Magento2 where your module is located.This is a fragment from the Magento Checkout module's
composer.json
:If you have your module in a separate repository and loaded via composer, then the above is the way to go. If you do not have it in a separate repository, then your module does not belong on
vendor/
but inapp/code/
.