Fatal error: Uncaught ReflectionException: Class config does not exist
Asked Answered
G

10

17

I'm working on an e-commerce project on Laravel 5.8, but since I accidently ran "laravel new" command on the project's folder I get this error when I'm trying to launch the project on a local server:

Fatal error: Uncaught ReflectionException: Class config does not exist in C:\wamp64\www\e-commerce\vendor\laravel\framework\src\Illuminate\Container\Container.php:788 Stack trace: 0 C:\wamp64\www\e-commerce\vendor\laravel\framework\src\Illuminate\Container\Container.php(788): ReflectionClass->__construct('config') 1 C:\wamp64\www\e-commerce\vendor\laravel\framework\src\Illuminate\Container\Container.php(667): Illuminate\Container\Container->build('config') 2 C:\wamp64\www\e-commerce\vendor\laravel\framework\src\Illuminate\Container\Container.php(615): Illuminate\Container\Container->resolve('config', Array) 3 C:\wamp64\www\e-commerce\vendor\laravel\framework\src\Illuminate\Foundation\Application.php(767): Illuminate\Container\Container->make('config', Array) 4 C:\wamp64\www\e-commerce\vendor\laravel\framework\src\Illuminate\Container\Container.php(1227): Illuminate\Foundation\Application->make('config') 5 C:\wamp64\www\e-commerce\vendor\laravel\framework\src\Illuminate\Log\LogManager.php(417): Illuminate\Container\C in C:\wamp64\www\e-commerce\vendor\laravel\framework\src\Illuminate\Container\Container.php on line 788"

The error on line 788 refers to that portion of code:

$reflector = new ReflectionClass($concrete)

This happened after I cloned my repo from Github. Now for every project that I try to run on a local server I get this error.

I tried "composer install", "composer update", "composer dump-autoload" but they all give the same error with this line at the end: "Script @php artisan package:discover --ansi handling the post-autoload-dump event returned with error code 255".

I checked the .env file to see if there was a namespace issue too, but there's none of it.

Thank you in advance for your help.

Gitt answered 30/8, 2019 at 12:30 Comment(5)
Was the repo up to date before you naffed your project folder?Powel
Modify your composer.json to remove any artisan script call out of the scripts section. Then try again.Pitt
composer update --no-scripts and then try composer updateSprout
RiggsFolly actually no, it wasn't.Gitt
composer update --no-scripts did the trick on my end, thanks @DilipHiraparaFernyak
C
24

Try to remove de files in:

cd bootstrap/cache/
rm -rf *.php

In this directory are the file that initializes the structure, cache directory that contains structure-generated files for performance optimization, such as files and route cache services.

Courthouse answered 30/8, 2019 at 13:7 Comment(2)
I tried all of the methods above but none of them worked. Can anyone provide me something else?Gitt
after deleting the files in boostrap/cache/.. i did composer dump-autoload.. and it worked for meDelao
J
5

You may check the following items

  1. Check whether your APP_NAME has space. If space is there, use it in quotes.
  2. run
rm -r /bootstrap/cache

to Delete everything from bootstrap/cache/ folder.

  1. run
composer dump-autoload

Hope it will work

Jamima answered 22/4, 2021 at 19:18 Comment(0)
A
2

I tried @gulCunha 's answer and it worked.

After that, you have to run composer update in order to create a new composer.lock and php artisan config:cache after that and you should be good to go.

Antediluvian answered 7/8, 2020 at 15:33 Comment(0)
G
1

Did you change the .env file,mistakenly I have added a "APP_NAME=aaa aa " with spaces, then checked every where, after that APP_NAME= changed without spaces, now working charm.

Guardant answered 28/2, 2021 at 15:30 Comment(0)
D
1

I was creating a new Laravel 9 project with composer and got the same error.

Fatal error: Uncaught ReflectionException: Class "config" does not exist in .../vendor/laravel/framework/src/Illuminate/Container/Container.php:875
Stack trace:
#0 .../vendor/laravel/framework/src/Illuminate/Container/Container.php(875): ReflectionClass->__construct('config')
#1 .../vendor/laravel/framework/src/Illuminate/Container/Container.php(756): Illuminate\Container\Container->build('config')
#2 .../vendor/laravel/framework/src/Illuminate/Foundation/Application.php(855): Illuminate\Container\Container->resolve('config', Array, true)
#3 .../vendor/laravel/framework/src/Illuminate/Container/Container.php(692): Illuminate\Foundation\Application->resolve('config', Array)
#4 .../vendor/laravel/framework/src/Illuminate/Foundation/Application.php(840): Illuminate\Container\Container->make('config', Array)
#5 .../vendor/laravel/framework/src/Illuminate/Container/Container.php(1415): Illuminate\Foundation\Application->make('config')
#6 .../vendor/laravel/framework/src/Illuminate/Log/LogManager.php(515): Illuminate\Container\Container->offsetGet('config')
#7 .../vendor/laravel/framework/src/Illuminate/Log/LogManager.php(566): Illuminate\Log\LogManager->getDefaultDriver()
#8 .../vendor/laravel/framework/src/Illuminate/Log/LogManager.php(119): Illuminate\Log\LogManager->parseDriver(NULL)
#9 .../vendor/laravel/framework/src/Illuminate/Log/LogManager.php(702): Illuminate\Log\LogManager->driver()
#10 .../vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php(274): Illuminate\Log\LogManager->log('error', 'substr(): Argum...', Array)
#11 .../vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(367): Illuminate\Foundation\Exceptions\Handler->report(Object(TypeError))
#12 .../vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(131): Illuminate\Foundation\Console\Kernel->reportException(Object(TypeError))
#13 .../artisan(37): Illuminate\Foundation\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#14 {main}

Next Illuminate\Contracts\Container\BindingResolutionException: Target class [config] does not exist. in .../vendor/laravel/framework/src/Illuminate/Container/Container.php:877
Stack trace:
#0 .../vendor/laravel/framework/src/Illuminate/Container/Container.php(756): Illuminate\Container\Container->build('config')
#1 .../vendor/laravel/framework/src/Illuminate/Foundation/Application.php(855): Illuminate\Container\Container->resolve('config', Array, true)
#2 .../vendor/laravel/framework/src/Illuminate/Container/Container.php(692): Illuminate\Foundation\Application->resolve('config', Array)
#3 .../vendor/laravel/framework/src/Illuminate/Foundation/Application.php(840): Illuminate\Container\Container->make('config', Array)
#4 .../vendor/laravel/framework/src/Illuminate/Container/Container.php(1415): Illuminate\Foundation\Application->make('config')
#5 .../vendor/laravel/framework/src/Illuminate/Log/LogManager.php(515): Illuminate\Container\Container->offsetGet('config')
#6 .../vendor/laravel/framework/src/Illuminate/Log/LogManager.php(566): Illuminate\Log\LogManager->getDefaultDriver()
#7 .../vendor/laravel/framework/src/Illuminate/Log/LogManager.php(119): Illuminate\Log\LogManager->parseDriver(NULL)
#8 .../vendor/laravel/framework/src/Illuminate/Log/LogManager.php(702): Illuminate\Log\LogManager->driver()
#9 .../vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php(274): Illuminate\Log\LogManager->log('error', 'substr(): Argum...', Array)
#10 .../vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(367): Illuminate\Foundation\Exceptions\Handler->report(Object(TypeError))
#11 .../vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(131): Illuminate\Foundation\Console\Kernel->reportException(Object(TypeError))
#12 .../artisan(37): Illuminate\Foundation\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#13 {main}
  thrown in .../vendor/laravel/framework/src/Illuminate/Container/Container.php on line 877
Script @php artisan package:discover --ansi handling the post-autoload-dump event returned with error code 255

But this time it was not about the cache. Regardless of what the errors suggest, the problem was actually caused by the following lines found in vendor/vlucas/phpdotenv/src/Util/Str.php

$converted = $encoding === null ?                                             
    @\mb_convert_encoding($input, 'UTF-8') :                                  
    @\mb_convert_encoding($input, 'UTF-8', $encoding);

It actually occurred as I didn't have Multibyte String enabled when I built my PHP binaries. After rebuilding PHP with --enable-mbstring, the problem went away.

Drawstring answered 10/6, 2022 at 2:36 Comment(0)
E
1

You should run the composer update command, and then php artisan optimize to clear the config cache and routes.

Etching answered 30/9, 2022 at 6:38 Comment(0)
C
0

Make sure your .env file is the exact same as in your local environment. Make sure that the values on your .env file don't have spaces. Those that have spaces should be wrapped in quotes

Charger answered 15/2, 2020 at 4:46 Comment(0)
L
0

I had a similar problem. Here is how I fixed it.

It started when I installed Toastr in my config/app.php providers. I had failed to add the trailing ",". Hence the problem.

Solution: Check the last package you installed. Check if you have added it correctly in the service providers.

Legitimate answered 28/10, 2021 at 20:25 Comment(0)
B
0

If you are getting this error when migrating a Lumen 5.8 web application to Laravel 5.8, when running php vendor/bin/phpunit, check if main Test\TestCase has use CreatesApplication; inside the class body, and not it's own function createApplication().

abstract class QdtTestCase extends BaseTestCase
{
    use CreatesApplication;

    /**
//     * Creates the application.
//     *
//     * @return Application
//     */
//    public function createApplication()
//    {
//        return require __DIR__ . '/../bootstrap/app.php';
//    }
}

You can copy this Test\CreatesApplication .php file from a fresh Laravel 5.8 project.

Alternatively, you could write:

abstract class QdtTestCase extends BaseTestCase
{
    // use CreatesApplication;

    /**
     * Creates the application.
     *
     * @return Application
     */
    public function createApplication()
    {
        $app = require __DIR__ . '/../bootstrap/app.php';

        $app->make(Kernel::class)->bootstrap();

        return $app;
    }
}

The "ReflectionException: Class config does not exist" error occurs isnside \Illuminate\Foundation\Testing\RefreshDatabase::usingInMemoryDatabase when calling config('database.default') or in \Illuminate\Foundation\Testing\Concerns\MakesHttpRequests::prepareUrlForRequest, when calling config('app.url').

Benally answered 22/5, 2023 at 11:39 Comment(0)
C
0

I tried all the answers here and none of them worked for me. I tried composer diagnose and that is how I discovered that I was not running the latest stable version of composer. I then run composer self-update and that finally solved my issue.

Cholera answered 30/5 at 13:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.