11

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.

RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
IbraProjects
  • 121
  • 1
  • 2
  • 5

9 Answers9

19

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.

guiCunha
  • 343
  • 1
  • 4
3

You may check the following items

  1. Check whether your APP_NAME has space. If space is there, use it in quotes.
  2. Delete everything from bootstrap/cache/ folder.
  3. run composer dump-autoload

Hope it will work

1

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.

Lohenrex
  • 49
  • 7
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.

Lasantha
  • 258
  • 1
  • 11
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.

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

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.

Dharman
  • 30,962
  • 25
  • 85
  • 135
Wanjila Abraham
  • 521
  • 1
  • 7
  • 17
0

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

Jeff Schaller
  • 2,352
  • 5
  • 23
  • 38
Dharmil
  • 3
  • 3
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').

Henk Poley
  • 729
  • 8
  • 17