Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

calebporzio's avatar

Composer Update on Deployment

So... If I install a package for instance: "laracasts/utilities", I am supposed to add the require line to composer.json and add the service provider to app.php: /Laracasts\Utilities\JavaScript\JavaScriptServiceProvider::class

If I add the class to the service provider list and then run the command "composer update" it gives me an error because that class is not found. No problem, comment out that line, install the package, uncomment the line and we are all set.

However, when I deploy the code and run a composer update on the staging / production server it will throw that error and I don't want to have to modify code other than just updating the code with git pull.

I hope that made sense. Kind of a chicken before egg thing, seems someone must have a good solution to this.

Thanks, Caleb

0 likes
5 replies
gstjohn's avatar
gstjohn
Best Answer
Level 10

When you run a composer update, composer runs a pre-update hook to have Laravel clear all compiled files. This boots Laravel which loads the IoC container and causes the missing class (JavaScriptServiceProvider) to report the specified error.

A composer install does not run anything in Laravel before it grabs the package, but it does have post-install hooks. However, by the time those run the package is available and the dependency is good.

All this to say that if you are running composer install in production you shouldn't have an issue.

calebporzio's avatar

Thanks for the replies. I think we are on the right track, but If I "composer install" it says nothing to install or remove because it is checking the Lock file. Any thoughts? I can run composer .update and it will re-write the lock file.

Thoughts?

gstjohn's avatar

That's fine to run a composer update locally during development, but your staging/prod environments should really have their versions locked which makes a composer install the right move. Does that answer your question?

calebporzio's avatar

Ok, I think I see now, the composer lock file would be update on the server as well. All good.

Thanks, Caleb

Please or to participate in this conversation.