roeben's avatar

Composer autoload doesn't seem to work

Hi,

I've got an Laravel project, and when I added packages with composer, everything worked out fine. Now I've added JWTAuth, and the site breaks down. I get the following error:

production.ERROR: exception 'Symfony\Component\Debug\Exception\FatalErrorException' with message 'Class 'JWTAuth' not found' in /home/sensornetw/apps/app/Http/Controllers/API/AuthenticateController.php:21

It seems the autoloader won't load the class. I've removed the vendor dir, composer.json and installed everything from scratch.

The problem only occurs on the production server. On my local dev computer, there is no problem.

0 likes
12 replies
phildawson's avatar

if you run composer dump-autoload does that help?

1 like
roeben's avatar

Nope, tried that a few times as well

sid405's avatar

@roeben and you're importing the class correctly before using it on AuthenticateController?

roeben's avatar

Well, shouldn't the autoloader do that? I use the correct namespace, if that is what you are asking. The local version confirms that, because there the class works without any problems.

sid405's avatar

Sue, but in config/app.php did you add to providers

'Tymon\JWTAuth\Providers\JWTAuthServiceProvider'

and then to facades

'JWTAuth' => 'Tymon\JWTAuth\Facades\JWTAuth'

and at the top of AuthenticateController

use JWTAuth;

Composer will not do that for you. It's not its job.

1 like
roeben's avatar

I got all this. Again, on localhost it works, so it seems there is not much wrong with the code..

sid405's avatar

@roeben and the package on the other server is installed through composer as well? Because of the code is fine, then you're dealing with other factors, which could be the missing package.

roeben's avatar

I removed the vendor directory a few times, reinstalled with composer. Ran all possible commands with composer, and checked everytime if the packages were downloaded.

If I check the vendor folder now on the server, the package is there, so why won't the autoader grab it?

sid405's avatar

When you removed the vendor folder, did you also remove composer.lock and then run

composer install

There's also the option

artisan clear-compiled
roeben's avatar

Yes, did all that too, did not work.

sid405's avatar

Then given the circumstances i don't know what else to suggest. It's either something extremely contorted or extremely overlooked, because from the replies of all the peeps here, you say you tried the common solutions. :/

roeben's avatar

I really can't figure it out. So I'll just write the code myself or use other packages.

Thanks for the help!

Please or to participate in this conversation.