4

How can I force composer to install modules in app/code instead of vendor directory in Magento 2?

I have few modules they strictly need to be install in app/code, but when I update them with composer, they install in vendor directory.

7

I'm answering my own question, so it will be beneficial for someone else later,

To be able to install in a custom path, your module must support composer/installers so add it to your module's require section, eg:

"require": {
   "magento/magento-composer-installer": "*",
   "composer/installers": "~1.0"
}

and then give your module a custom path in extra section, where you want it to be installed. Eg:

"extra": {
   "installer-paths": {
      "app/code/Vendor/Module": ["vendor/module"]
   }
 }

and your module type must be "type": "magento-library" not "type": "magento2-module" (don't worry changing the type will not break anything, it'll still work like before)

so the complete json for the module will be like something this

{
    "name": "vendor/module",
    "description": "some description about your module",
    "require": {
        "magento/magento-composer-installer": "*",
        "composer/installers": "~1.0"
    },
    "type": "magento-library",
    "version": "1.0.0",
    "license": [
        "OSL-3.0",
        "AFL-3.0"
    ],
    "extra": {
        "installer-paths": {
            "app/code/Vendor/Module": ["vendor/module"]
        }
    }
}

and just to be sure, add it to your main composer.json's extra section too, this maybe optional but I have added it anyway.

"extra": {
   "magento-force": "override",
     "installer-paths": {
       "app/code/Vendor/Module": ["vendor/module"]
   }
 }

Then run composer update, so it will install your module in app/code or your given path.

  • not working on m2.2.2 – Sunil Verma Feb 6 '18 at 13:35
  • Using this method on 2.2 E still adds the module to the vendor folder. – LucasMaliszewski Jun 11 '18 at 17:29
1

instead of using composer you may extract file and paste it in to app/code/ create a folder structure like Vendorename/Modulename as in registration.php

  • 2
    No my current requirement is to use it with composer, anyway i figured it out if you use "extra": { "map": [ [ "*", "Vendor\/Module_Name" ] ] } it does add the module to app/code but it also in vendor – nuwaus Aug 9 '17 at 4:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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