Php – How to remove unused dependencies from composer


I installed a package with composer, and it installed many other packages as dependencies.

Now I uninstalled the main package with composer remove packageauthor/packagename, but all the old dependencies were not removed. I expected composer to clean up and only keep packages that are required according to composer.json and their dependencies.

How can I force composer to clean up and remove all unused packages ?

Best Answer

The right way to do this is:

composer remove jenssegers/mongodb --update-with-dependencies

I must admit the flag here is not quite obvious as to what it will do.


composer remove jenssegers/mongodb

As of v1.0.0-beta2 --update-with-dependencies is the default and is no longer required.

Related Question