framework: Uncaught ReflectionException: Class env does not exist

  • Laravel Version: 5.7.15
  • PHP Version: 7.2.12
  • Database Driver & Version: Mariadb 10.2

Description:

PHP Fatal error: Uncaught ReflectionException: Class env does not exist in /var/www/project/vendor/laravel/framework/src/Illuminate/Container/Container.php:779 Stack trace: #0 /var/www/project/vendor/laravel/framework/src/Illuminate/Container/Container.php(779): ReflectionClass->__construct('env') #1 /var/www/project/vendor/laravel/framework/src/Illuminate/Container/Container.php(658): Illuminate\Container\Container->build('env') #2 /var/www/project/vendor/laravel/framework/src/Illuminate/Container/Container.php(609): Illuminate\Container\Container->resolve('env', Array) #3 /var/www/project/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(735): Illuminate\Container\Container->make('env', Array) #4 /var/www/project/vendor/laravel/framework/src/Illuminate/Container/Container.php(1222): Illuminate\Foundation\Application->make('env') #5 /var/www/project/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(485): Illuminate\Container\Container-> in /var/www/project/vendor/laravel/framework/src/Illuminate/Container/Container.php on line 779

Steps To Reproduce:

php artisan

I followed the upgrade guide, maybe i missed something, i think not.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 31 (2 by maintainers)

Most upvoted comments

put dd($exception); in App\Exceptions\Handler::report() It gives you a better error message. there was an error in filesystem config for me!

I’ve runned

php artisan clear php artisan config:clear

Solved for me

For someone still having the issue, it can be solved adding

<server name="TELESCOPE_ENABLED" value="false"/> in phpunit.xml.

If you are upgrading to Laravel 6, the problem may be in the missing str_slug() function in configs, replace it with Str:slug()

I’m not using telescope package, but i’ve received the same exception on every php artisan call. I didn’t understand what code block crashes. Over internet there are many resolutions with cache cleaning. Those users received the same message while running phpunit command. I’ve tried to run phpunit and received an error related to configuration of one of packages that i’ve used. So I fixed package config problem and phpunit command runs well. Also, php artisan runs OK for now. Hope my solution will be useful to someone.

Still getting same issue.

Laravel 8.54

image

Can you first please try one of the following support channels? If you can actually identify this as a bug, feel free to report back.

Also check the issue tracker if your issue can be found somewhere here: https://github.com/laravel/framework/issues?q=is%3Aissue+Class+env+does+not+exist+is%3Aclosed

Are you using Telescope? Is this the problem you’re experiencing? https://github.com/laravel/telescope/issues/347

I solved the same by updating the composer

composer update

put dd($exception); in App\Exceptions\Handler::report() It give you a better error message. there was an error in filesystem config for me!

super thanks man

What I found: if you changed your config/app.php or any file under config/ and use something that don’t exists (ie, refering to a non-existing class, forgetting to use “::class” to refering to a class, don’t separating array keys with “,”, and so on) you’ll face this error. Double check if your files have any errors

put dd($exception); in App\Exceptions\Handler::report() It give you a better error message. there was an error in filesystem config for me!

Really usefull … thanks man

My sentry tell me the error becouse of this line: Screenshot from 2022-01-19 17-42-59

I just changing my TelescopeServiceProvider file from this

Telescope::filter(function (IncomingEntry $entry) {
            if ($this->app->environment('local') || config('telescope.enabled', false)) {
                return true;
            }

to this one:

Telescope::filter(function (IncomingEntry $entry) {
            if (config('app.env')=='local' || config('telescope.enabled', false)) {
                return true;
            }

put dd($exception); in App\Exceptions\Handler::report() It give you a better error message. there was an error in filesystem config for me!

First of all Huuuuuge thanks man. Everyone should try this. In my case the error was due to a stray character in one of my config file messing with parsing. I fixed it and the error was gone This was the actual error in my case

^ ParseError {#148 #message: “syntax error, unexpected ‘[’, expecting ‘]’” #code: 0 #file: “./config/adminlte.php” #line: 250 trace: { ./config/adminlte.php:250 {

May be useful for you @henriquek3 https://github.com/laravel/framework/issues/39347

If you have any exception has been thrown on any config file, you’ll face this error. I think it is bug of Laravel 😄

put dd($exception); in App\Exceptions\Handler::report() It give you a better error message. there was an error in filesystem config for me!

same here, its an error on my logger config file

put dd($exception); in App\Exceptions\Handler::report() It give you a better error message. there was an error in filesystem config for me!

I accidentally removed Jetstream from my composer.json 😂 This gave the ‘env’ error on any artisan command… but your solution made clear to me that I was missing Fortify all of a sudden. Big ups @athamidn

put dd($exception); in App\Exceptions\Handler::report() It give you a better error message. there was an error in filesystem config for me!

Thanks so much for everything, I was frustrated 🍡

I faced this issue and found issue in config folder > constants file I was wrote “asset(‘/’)” function in config file, we can’t write such functions in config.

Hope this answer will some one who stuck like this errors.

@athamidn Super star, thanks! This was tripping me up too; was referencing a constant in my config files defined in a database seeder (which had changed to being namespace in a laravel 8 update).