2

I'm trying to install my custom module using composer.json file and after run composer update command my custom module installed successfully in magento2.

Actually I want to install my custom module in app/code directory using composer.json and I have found some solution from dedicated developers and add extra section in my composer.json as following:

"extra": {
    "map": [
        [
            "*",
            "Gotham/Customimgattr"
        ]
    ]
}

Using the above code snippet my module added in app/code folder but also added in vendor directory. So anyone knows how to install custom module in app/code folder only not in vendor using composer.json file? Thanks in advance. My composer.json file:-

{
    "name": "myproject/mymodule",
    "description": "Upload Db Schema",
    "license": [
        "OSL-3.0",
        "AFL-3.0"
    ],
     "require": {
        "php": "7.0.2|7.0.4|~7.0.6|~7.1.0"
      },
      "type": "magento2-module",
      "version": "1.0.0",
      "extra": {
        "map": [
            [
                "*",
                "Gotham/Customimgattr"
            ]
        ]
      }
}

2 Answers 2

0

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. I am referring form this answer How to install modules in app/code with composer in Magento 2

0

You could try the following:

In your root composer.json file, under repositories add:

"local-packages": {type": "path", url": "./app/code/*"}

Then add your module under app/code and require it via composer.

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.