ChatGPT解决这个技术问题 Extra ChatGPT

Is there a way to uninstall dev dependencies with composer?

I want to uninstall (and not remove from my composer.json) dev dependencies on a project.

Is there a simple way to do this ?

What have you tried so far? Where are you stuck?

S
Seldaek

Running install or update with --no-dev should now remove dev requirements and their dependencies.

Original answer for historical purposes:

Actually no. You can manually rm -rf them from the vendor dir of course, but composer offers no way to uninstall the dev requirements after you did an install with --dev. It's not a huge use case but could warrant a new command line switch, if you would like to report an issue on github.


This behaviour has now changed. You just need to add the --dev switch to composer update to physically remove dev packages
Just to be clear, the command is composer install --no-dev. This will remove the dev packages leaving composer.json and composer.lock files intact.
l
localheinz

You can use following command after removing the dependencies in composer.json file.

composer update

Pay attention because that can cause that all that is in "require" is uninstalled and removed
In some instances, it may be advisable to run composer install instead.
Please add some explanation to your answer such that others can learn from it. This should also contain a warning that this command will possibly change the versions of many other packages
B
Blizz

Came over this question when looking for the same answer. You can now uninstall installed dev dependencies by simply doing:

composer --no-dev update

It will remove all dev packages that it finds. Though it would interest people landing here the same way I did :)


Not the most intuitive command line option..but it is there! Thanks!
It's not a good idea if you do not strongly fixed versions of other packages because not only remove dev deps, but may update current versions of others packages. Not consistent for production use.
Sure, but that is completely unrelated to the original question. Besides, in production you should NEVER use composer update, always use composer install with a committed composer.lock file. That being said: you can also use the option for that command. Please refer to the accepted answer that was modified to also include this: Seldaek is the author of composer.
This really is dangerous to run the suggested command on production. The update command may update the packages you were not intended to update while you only wanted to remove the dev dependencies from the vendor directory.
If you use composer in production as intended you'll have a composer.lock-file there. That means that this command will update exactly 0 dependencies and is perfectly safe to use. Btw, the accepted answer (which was updated with the same information after I put this here) is from the author of composer.
S
SandroMarques

This is not the strict answer but may help someone.

To remove a specific dev dependency:

composer remove --dev squizlabs/php_codesniffer

S
Syscall

I answered later but it could help someone else: composer remove friendsofsymfony/elastica-bundle (for example)