0

I am trying to develop simple Magento 2 module. Accoding to Composer integration guide I had to put all my dependencies into composer.json file into my module root. According to Default File Structure Guide I had to put my code in app/code directory (on development stage, before release). So the question is how to enable magento to load me dependencies from app/code/vendor-name/package-name/composer.json file?

  1. If I run

bin/magento setup:upgrade

my module is enabled, but dependencies are not loaded to /vendor

  1. If I run

composer update

from magento root dir, my module dependencies are still not loaded

  1. If I run

composer install

from app/code/[my module dir], dependencies are loaded into app/code/[my module dir]/vendor, but not into [magento root]/vendor dir

What is the best practice for module development with composer dependencies?

0

This is the basic mistake we do. composer update will include the module to composer.json and composer.lock ONLY IF the module is installed by composer.

In your case you have developed a new module locally which has a composer.json. As your module is not installed by composer it has been manually created in app/code/ location composer has no track of your newly developed module.

So if your module have a third party dependency you have to use composer required command in the Magento root to update the composer.json and composer.lock

composer require xyz/abc

Similar post Magento2: How to include third pary module through composer.json in custom module

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.