Composer : Why some of my packages got automatically removed on installing a new package

Viewed 571

My composer status while installing the new package

I tried installing stripe package on yii2 via composer. It got installed successfully but also removed some of the packages automatically. I didn't edit composer.json or lock file, I just execute the composer require command to install the package. Why the composer removed those packages and how can I recover them back? Is there any way to prevent it in future? Thanks!

1 Answers

Say your project A requires dependency B.

Version 1.1.x of dependency B requires package C.

Now if you update to version 1.2.x of dependency B which does NOT depend on package C anymore composer will automatically detect the orphaned dependency and therefore remove package C.

If you still want package C to be available to your application after the update you need to explicitly require it - making it an explicit dependency instead of an implicit one (installed as a dependency of another package).

composer automatically updates the other dependencies of your project (respecting the existing version constraints your composer.json) if you invoke composer require.

To prevent automatic dependency updates use:

composer require --no-update <package>
Related