lithium's avatar

Autoloading weird issue? :~p

Lumen Version: Lumen (5.4.6)

This is probably not related to the framework but here's what happening.

If I run composer dump-autoload I am getting

"Class App\Contracts\DemoContract does not exist"

Then if I run composer dump-autoload -o

no issues, DemoContract is found.

Finally, if I run composer again dump-autoload without the -optimize flag

I am back to Class App\Contracts\DemoContract does not exist

Any idea what's happening? what am I missing?

Thank you

0 likes
4 replies
AddWebContribution's avatar

I think you should update your composer.json file

"autoload": {
    "classmap": [
        "app/database/"   // PATH TO YOUR MIGRATIONS FOLDER
    ],
}

Then after run three command

php artisan clear-compiled 
composer dump-autoload
php artisan optimize

Hope it's work for you !

EventFellows's avatar

In at least one of the places where you reference App\Contracts\DemoContract laravel cannot find it (that would also happen if you use a part of your application that has the wrong reference.

Here are some common reasons

  • the Class does not exist
  • Class does not exist in that location
  • Namespacing is wrong/ missing
  • File name is wrong
  • Spelling of Class in the file is wrong
  • Cache is not cleared

I'd do a systemwide search for the class in the exact writing you have in your error and check it.

lithium's avatar

But the class does exist and it's found when using dump-autoload with the -optimize flag.

The issue arises only when I ran dump-autoload without the -o flag

EventFellows's avatar
Level 16

AFAIK: if you run dump autoload with the -opitmize flag it does NOT load the application during dump-autoload, hence it does not look for the class you are missing. And as a result it does not throw an error.

But not throwing this error is not to be mis-interpreted as it works - it just does not realize it missing.

Your error clearly states 'Class App\Contracts\DemoContract does not exist' so for the way and the place your app tries to resolve it, the class DOES NOT EXISTS.

I remember having weird situation like this for different reasons, soemtimes even within that class (e.g. a missing closing }) that make the class 'non existend' for the way the app looks for it eventhough I could find it with my own eyes in the folder structure...

Please or to participate in this conversation.