logo
podcast Podcast
get help Get Unstuck

Don't explicitly install dependencies if you don't need to

Pay attention to the dependencies Laravel or other packages are already bringing in. You may be pinning them to an older version without realizing it.

Joel Clermont
Joel Clermont
2023-09-04

I was working in a newly-inherited application, and one of my first tasks was to set up Sentry, so we could monitor exceptions in production, and get a feel for existing performance issues. Installing the package worked fine, but when I went to run artisan sentry:test to generate a test error, it failed with a cURL error.

Digging a little deeper, it turns out there was a bug in a version of the http client package related to specific versions of cURL and PHP. This error was fixed months ago, but I was still getting it and I had just installed the Sentry package.

Looking closer at composer.json, I saw that the previous developer had directly installed symfony/http-client even though this dependency was already brought in by Laravel. This top-level reference in composer.json was effectively pinning it, and by extension everything that depended on it, like my Sentry package.

The solution was to remove this top-level reference with composer remove symfony/http-client. It doesn't actually uninstall the package since Laravel has it as a dependency, but now when I re-installed Sentry, it could update the underlying dependencies to pull in the newer version with the curl fix. I'm not entirely sure why the previous developer installed it this way, but it sparked the idea for today's tip.

Take a look at your composer.json and make sure you're not explicitly installing dependencies if you don't have a very clear reason for doing so. It will likely save you some grief down the road.

Here to help,

Joel

P.S. You think this tip is good? You should try our free book of even more Laravel tips to make your application a little bit better.

Toss a coin in the jar if you found this helpful.
Want a tip like this in your inbox every weekday? Sign up below 👇🏼
email
No spam. Only real-world advice you can use.