简体   繁体   English

致命错误:未捕获的 ReflectionException:Class 配置不存在

[英]Fatal error: Uncaught ReflectionException: Class config does not exist

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:我正在 Laravel 5.8 上开发一个电子商务项目,但由于我不小心在项目文件夹上运行了“laravel new”命令,所以当我尝试在本地服务器上启动该项目时出现此错误:

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->m致命错误:未捕获的 ReflectionException:Class 配置在 C 中不存在:\wamp64\www\e-commerce\vendor\laravel\framework\src\Illuminate\Container\Container.php:788 堆栈跟踪:0 881037565863648:\ \电子商务\供应商\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->m ake('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" ake('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 第 788 行”

The error on line 788 refers to that portion of code:第 788 行的错误指的是那部分代码:

$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.这发生在我从 Github 克隆我的 repo 之后。现在对于我尝试在本地服务器上运行的每个项目,我都会收到此错误。

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".我尝试了“composer install”、“composer update”、“composer dump-autoload”,但它们都在最后这一行给出了相同的错误:“Script @php artisan package:discover --ansi handling the post-autoload-dump事件返回错误代码 255”。

I checked the.env file to see if there was a namespace issue too, but there's none of it.我检查了 .env 文件以查看是否也存在名称空间问题,但没有。

Thank you in advance for your help.预先感谢您的帮助。

Try to remove de files in:尝试删除 de 文件:

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.在这个目录中是初始化结构的文件,缓存目录包含了用于性能优化的结构生成文件,例如文件和路由缓存服务。

I tried @gulCunha 's answer and it worked.我尝试了@gulCunha 的答案,它奏效了。

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.之后,您必须运行composer update以创建一个新的composer.lockphp artisan config:cache ,然后您应该一切顺利。

您是否更改了.env文件,错误地我添加了一个带有空格的"APP_NAME=aaa aa " ,然后检查了每个位置,之后APP_NAME=更改为不带空格,现在工作魅力。

You may check the following items您可以检查以下项目

  1. Check whether your APP_NAME has space.检查您的 APP_NAME 是否有空间。 If space is there, use it in quotes.如果有空格,请在引号中使用。
  2. Delete everything from bootstrap/cache/ folder.从 bootstrap/cache/ 文件夹中删除所有内容。
  3. run composer dump-autoload运行composer dump-autoload

Hope it will work希望它会起作用

Make sure your .env file is the exact same as in your local environment.确保您的 .env 文件与本地环境中的完全相同。 Make sure that the values on your .env file don't have spaces.确保 .env 文件中的值没有空格。 Those that have spaces should be wrapped in quotes那些有空格的应该用引号引起来

I had a similar problem.我有一个类似的问题。 Here is how I fixed it.这是我修复它的方法。

It started when I installed Toastr in my config/app.php providers.当我在我的 config/app.php 提供程序中安装 Toastr 时,它就开始了。 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.检查您是否在服务提供商中正确添加了它。

I was creating a new Laravel 9 project with composer and got the same error.我正在使用 composer 创建一个新的 Laravel 9 项目并得到了同样的错误。

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不管错误提示什么,问题实际上是由在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.这实际上是因为我在构建 PHP 二进制文件时没有启用多字节字符串 After rebuilding PHP with --enable-mbstring , the problem went away.使用--enable-mbstring重建 PHP 后,问题就消失了。

You should run 'composer update' command, and then 'php artisan optimize' to clear the config cache and routes.您应该运行“composer update”命令,然后运行“php artisan optimize”以清除配置缓存和路由。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 致命错误:未捕获的 ReflectionException:Class “env”不存在 - Fatal error: Uncaught ReflectionException: Class "env" does not exist Laravel-未捕获的ReflectionException:类日志不存在-配置错误 - Laravel - Uncaught ReflectionException: Class log does not exist - Config error 将我的 laravel api 上传到 000webhost 时出现此错误致命错误:未捕获的反射异常:Class“配置”不存在 - i have this error when uploading my laravel api to 000webhost Fatal error: Uncaught ReflectionException: Class "config" does not exist Laravel 5.1.11致命错误:消息为“类日志不存在”的未捕获异常“ Re​​flectionException” - Laravel 5.1.11 Fatal error: Uncaught exception 'ReflectionException' with message 'Class log does not exist' Laravel:致命错误:未捕获反射异常:Class App\Http\Kernel 不存在 - Laravel : Fatal error: Uncaught ReflectionException: Class App\Http\Kernel does not exist ReflectionException:类配置不存在 - ReflectionException: Class config does not exist Laravel错误:未捕获的ReflectionException:类App \\ Http \\ Kernel不存在 - Laravel Error : Uncaught ReflectionException: Class App\Http\Kernel does not exist 未捕获的 ReflectionException:Class 请求在 Jenkins 中不存在 - Uncaught ReflectionException: Class request does not exist in Jenkins Laravel 抛出 ReflectionException:类配置不存在 - Laravel throws ReflectionException: Class config does not exist 致命错误:未捕获的 ReflectionException:方法 get_site_editor_type 不存在于...第 45 行 - Fatal error: Uncaught ReflectionException: Method get_site_editor_type does not exist in... on line 45
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM