laravel L5.1 类 App\Console\Kernel 不存在
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33761186/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
L5.1 Class App\Console\Kernel does not exist
提问by Rafal Olszewski
whenever im trying to run composer update
or require
, or php artisan
- i get error
每当我试图运行composer update
或require
,或php artisan
- 我得到错误
root@websites:/var/www/rafdev.ovh/html/msvixen# composer update
Loading composer repositories with package information
Updating dependencies (including require-dev)
Nothing to install or update
Generating autoload files
> php artisan clear-compiled
PHP Fatal error: Uncaught exception 'ReflectionException' with message 'Class App\Console\Kernel does not exist' in /var/www/rafdev.ovh/html/msvixen/vendor/laravel/framework/src/Illuminate/Container/Container.php:737
Stack trace:
#0 /var/www/rafdev.ovh/html/msvixen/vendor/laravel/framework/src/Illuminate/Container/Container.php(737): ReflectionClass->__construct('App\Console\Ker...')
#1 /var/www/rafdev.ovh/html/msvixen/vendor/laravel/framework/src/Illuminate/Container/Container.php(627): Illuminate\Container\Container->build('App\Console\Ker...', Array)
#2 /var/www/rafdev.ovh/html/msvixen/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(674): Illuminate\Container\Container->make('App\Console\Ker...', Array)
#3 /var/www/rafdev.ovh/html/msvixen/vendor/laravel/framework/src/Illuminate/Container/Container.php(216): Illuminate\Foundation\Application->make('App\Console\Ker...', Array)
#4 /var/www/rafdev.ovh/html/msvixen/vendor/laravel/framework/src/Illuminate/Container/Container.php(734): Illuminate\Container\Cont in /var/www/rafdev.ovh/html/msvixen/vendor/laravel/framework/src/Illuminate/Container/Container.php on line 737
Script php artisan clear-compiled handling the post-update-cmd event returned with an error
[RuntimeException]
Error Output: PHP Fatal error: Uncaught exception 'ReflectionException' with message 'Class App\Console\Kernel does not exist' in /var/www/rafdev.ovh/html/msvixen/vend
or/laravel/framework/src/Illuminate/Container/Container.php:737
Stack trace:
#0 /var/www/rafdev.ovh/html/msvixen/vendor/laravel/framework/src/Illuminate/Container/Container.php(737): ReflectionClass->__construct('App\Console\Ker...')
#1 /var/www/rafdev.ovh/html/msvixen/vendor/laravel/framework/src/Illuminate/Container/Container.php(627): Illuminate\Container\Container->build('App\Console\Ker...', Ar
ray)
#2 /var/www/rafdev.ovh/html/msvixen/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(674): Illuminate\Container\Container->make('App\Console\Ker...',
Array)
#3 /var/www/rafdev.ovh/html/msvixen/vendor/laravel/framework/src/Illuminate/Container/Container.php(216): Illuminate\Foundation\Application->make('App\Console\Ker...',
Array)
#4 /var/www/rafdev.ovh/html/msvixen/vendor/laravel/framework/src/Illuminate/Container/Container.php(734): Illuminate\Container\Cont in /var/www/rafdev.ovh/html/msvixen/
vendor/laravel/framework/src/Illuminate/Container/Container.php on line 737
update [--prefer-source] [--prefer-dist] [--dry-run] [--dev] [--no-dev] [--lock] [--no-plugins] [--no-custom-installers] [--no-autoloader] [--no-scripts] [--no-progress] [--with-dependencies] [-v|vv|vvv|--verbose] [-o|--optimize-autoloader] [-a|--classmap-authoritative] [--ignore-platform-reqs] [--prefer-stable] [--prefer-lowest] [--] [<packages>]...
root@websites:/var/www/rafdev.ovh/html/msvixen#
and this is my composer.json
file
这是我的composer.json
文件
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": [
"framework",
"laravel"
],
"license": "MIT",
"type": "project",
"require": {
"php": ">=5.5.9",
"laravel/framework": "5.1.*",
"skmetaly/laravel-twitch-restful-api": "dev-master",
"laravelcollective/html": "5.*"
},
"require-dev": {
"fzaninotto/faker": "~1.4",
"mockery/mockery": "0.9.*",
"phpunit/phpunit": "~4.0",
"phpspec/phpspec": "~2.1"
},
"autoload": {
"classmap": [
"database"
],
"psr-4": {
"App\": "app/"
}
},
"autoload-dev": {
"classmap": [
"tests/TestCase.php"
]
},
"scripts": {
"post-install-cmd": [
"php artisan clear-compiled",
"php artisan optimize"
],
"pre-update-cmd": [
],
"post-update-cmd": [
"php artisan clear-compiled",
"php artisan optimize"
],
"post-root-package-install": [
"php -r \"copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"php artisan key:generate"
]
},
"config": {
"preferred-install": "dist"
}
}
回答by Trip
To better understand this (succinctly): Compiled.php has what amounts to a snapshot map of your existing application. A composer update has the ability to change the location or existence of classes mapped in the snapshot. When this happens, compiled.php can't find the classes in its map. (This is why 'clear-compiled' should almostalways be run in the pre-update-cmd block.)
为了更好地理解这一点(简洁地):Compiled.php 具有相当于现有应用程序的快照映射的内容。Composer 更新能够更改快照中映射的类的位置或存在。发生这种情况时,compiled.php 无法在其映射中找到类。(这就是为什么 'clear-compiled' 应该几乎总是在 pre-update-cmd 块中运行。)
This problem generally happens during upgrades or abnormal file-system changes that essentially invalidate compiled.php. The good news is that there is a way around this.
这个问题通常发生在升级或异常的文件系统更改期间,这些更改基本上使compiled.php 无效。好消息是有办法解决这个问题。
If it is just your compiled.php that is messed up, you can manually delete it and try the composer update again. This is normally done with "php artisan clear-compiled" but since artisan uses compiled.php, this command blocks itself. Hence the need to manually remove the compiled.php file.
如果只是你的compiled.php搞砸了,你可以手动删除它,然后再次尝试composer更新。这通常是通过“php artisan clear-compiled”完成的,但是由于artisan使用了compiled.php,这个命令会阻止自己。因此需要手动删除compiled.php 文件。
$ rm bootstrap/cache/compiled.php
$ composer update
If you still get errors about missing classes, it means there's something missing in your filesystem that is expected elsewhere. This next part is a little tricky, but it works.
如果您仍然收到有关缺少类的错误,则意味着您的文件系统中缺少其他地方预期的某些内容。下一部分有点棘手,但它有效。
Based on what I'm looking at in your composer.json file, you will likely need to move the "php artisan clear-compiled" command from the 'post-update-cmd' to the 'pre-update-cmd' block. This way the compiled.php file doesn't block artisan as described above after composer updates your files.
根据我在您的 composer.json 文件中看到的内容,您可能需要将“php artisan clear-compiled”命令从“post-update-cmd”移动到“pre-update-cmd”块。这样,在 composer 更新您的文件后,compiled.php 文件不会像上面描述的那样阻止 artisan。
The full process for de-funking this situation is:
消除这种情况的完整过程是:
- Manually delete compiled.php (usually in /bootstrap/cache for L5.1)
- Make sure no artisan commands are run in the "pre-update-cmd" block of your composer.json (for you specifically, this is not a problem)
- Run composer update
- Put back any removed artisan commands in the "pre-update-cmd" block of your composer.json (for you specifically, just move clear-compiled from post to pre)
- 手动删除compiled.php(L5.1通常在/bootstrap/cache中)
- 确保在 composer.json 的“pre-update-cmd”块中没有运行 artisan 命令(特别是对你来说,这不是问题)
- 运行作曲家更新
- 将所有删除的工匠命令放回 composer.json 的“pre-update-cmd”块中(特别是对于您,只需将 clear-compiled 从 post 移到 pre)
If you have continued issues, please comment.
如果您还有其他问题,请发表评论。
回答by Rafal Olszewski
The problem was with namespaces. I didn't even realize it was it, I used php artisan app:name myname
before, and it updated files, but it didn't update composer.json
file. So I reverted every file that it changed namespace in - and now it works.
问题在于命名空间。我什至没有意识到它是它,我php artisan app:name myname
以前使用过,它更新了文件,但它没有更新composer.json
文件。所以我恢复了它改变命名空间的每个文件 - 现在它可以工作了。
Silly but how time consuming...
愚蠢,但多么耗时......