脚本@php artisan package:discover 处理返回错误代码 255 的 post-autoload-dump 事件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/50840960/
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
Script @php artisan package:discover handling the post-autoload-dump event returned with error code 255
提问by Ghyath Darwish
I moved my project from desk to another.
When I run php artisan
it does not work.
我将我的项目从办公桌移到另一个办公桌。
当我运行php artisan
它不起作用。
I tried to run composer update
, but it returns the error
我试图运行composer update
,但它返回错误
Script @php artisan package:discover handling the post-autoload-dump event returned with error code 255
脚本@php artisan package:discover 处理返回错误代码 255 的 post-autoload-dump 事件
回答by Oginga Michael
This is how I solved this after an upgrade from laravel version 6.x - 7.x:
这是我从 laravel 版本 6.x - 7.x 升级后解决这个问题的方法:
In App\Exceptions\Handler
changed
在App\Exceptions\Handler
改变
//Use Exception;
Use Throwable;
Then methods to accept instances of Throwable
instead of Exceptions
as follows:
然后方法来接受Throwable
代替的实例Exceptions
如下:
//public function report(Exception$exception);
public function report(Throwable $exception);
//public function render($request, Exception $exception);
public function render($request, Throwable $exception);
In config\session.php
:
在config\session.php
:
//'secure' => env('SESSION_SECURE_COOKIE', false),
'secure' => env('SESSION_SECURE_COOKIE', null),
Then run composer update
然后运行 composer update
回答by Samuel
I solved the problem this way:
我是这样解决问题的:
cd bootstrap/cache/
rm -rf *.php
The bootstrap directory contains the app.php file that initializes the structure. This directory also houses a cache directory that contains structure-generated files for performance optimization, such as files and route cache services. Laravel stores configuration files, provider, and cached services to optimize the fetching of this information. The problem with me was when the other developer ran the 'php artisan config: cache' command on your machine and since the cache folder contains files that can be deleted, I deleted them and solved the problem.
bootstrap 目录包含初始化结构的 app.php 文件。该目录还包含一个缓存目录,其中包含用于性能优化的结构生成文件,例如文件和路由缓存服务。Laravel 存储配置文件、提供程序和缓存服务以优化这些信息的获取。我的问题是当其他开发人员在您的机器上运行 'php artisan config: cache' 命令时,由于缓存文件夹包含可以删除的文件,我删除了它们并解决了问题。
回答by Arm092
If this happened after Laravel update from 6.x to 7.x, then this could be due to the update of Symfony. See the upgrade guide of this part: https://laravel.com/docs/7.x/upgrade#symfony-5-related-upgrades
如果这发生在 Laravel 从 6.x 更新到 7.x 之后,那么这可能是由于 Symfony 的更新。参见本部分升级指南:https: //laravel.com/docs/7.x/upgrade#symfony-5-related-upgrades
回答by nobuhiroharada
Do you have .env file in your new project?
你的新项目中有 .env 文件吗?
I had same error message. When I add .env file, error is gone.
我有同样的错误信息。当我添加 .env 文件时,错误消失了。
success message like this.
这样的成功信息。
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover
Discovered Package: fideloper/proxy
Discovered Package: ixudra/curl
Discovered Package: laravel/tinker
Discovered Package: nesbot/carbon
Discovered Package: socialiteproviders/manager
Package manifest generated successfully.
I hope this will help you.
我希望这能帮到您。
回答by Y. Joy Ch. Singha
I got the same problem in Win 8 and solve it:
我在 Win 8 中遇到了同样的问题并解决了它:
Here is the steps.
这是步骤。
Step-1: Go to your project directory
步骤 1:转到您的项目目录
Step-2: And type command cd bootstrap/cache/
步骤 2:并输入命令 cd bootstrap/cache/
Step-3: Again type command del -rf *.php
步骤 3:再次输入命令 del -rf *.php
Step-4: Update your composer composer update
第 4 步:更新您的作曲家 composer update
Step-5: Now you are done: php artisan serve
第 5 步:现在你完成了: php artisan serve
Thanks.
谢谢。
回答by Sanya
maybe you have an error in the project code (for example, in routes or controller). This may be one of the reasons for this error.
也许您在项目代码中有错误(例如,在路由或控制器中)。这可能是此错误的原因之一。
In my project, the web.php file has a syntax error. I defined this when I started the php artisan command
在我的项目中,web.php 文件有语法错误。我在启动 php artisan 命令时定义了这个
C:\OSPanel\domains\lara.shop.loc>php artisan
In web.php line
syntax error, unexpected end of file
回答by leo
I had this same problem when running composer update
in a Laravel project. In the package.json it's configured to run artisan package:discover
, which failed with:
我composer update
在 Laravel 项目中运行时遇到了同样的问题。在 package.json 中它被配置为 run artisan package:discover
,它失败了:
Class 'Symfony\Component\Translation\Translator' not found in vendor/nesbot/carbon/src/Carbon/Translator.php on line 18
Class 'Symfony\Component\Translation\Translator' not found in vendor/nesbot/carbon/src/Carbon/Translator.php on line 18
When I looked in the vendor/symfony/translation
directory I found that it was completely empty, which explained the error.
当我查看vendor/symfony/translation
目录时,我发现它完全是空的,这就解释了错误。
The solution was to completely delete the vendor
directory and then re-run composer update
. This was the only way that I was able to make composer install the missing files.
解决办法是彻底删除vendor
目录,然后重新运行composer update
。这是我能够让 composer 安装丢失文件的唯一方法。
回答by Axbor Axrorov
This is not an actual error. If you look a bit above you'll see the actual error. In my case, there was an error in my code:
这不是实际错误。如果你看上面一点,你会看到实际的错误。就我而言,我的代码中有错误:
PHP Fatal error: Declaration of
App\Exceptions\Handler::render($request, App\Exceptions\Exception $exception)
must be compatible with
Illuminate\Foundation\Exceptions\Handler::render($request, Throwable $e)
It is not possible to tell you what is actually a problem in your code, so you have to look real reason for this error in your stack trace.
无法告诉您代码中的实际问题是什么,因此您必须在堆栈跟踪中查看此错误的真正原因。
回答by Federico
nothing worked. So I installed a new project, and I read Handler.php in App\Exceptions, it was different, probably because I copied some solution and Internet and deleted the following:
没有任何效果。于是我新安装了一个项目,在App\Exceptions中读取Handler.php,结果不一样,可能是我复制了一些解决方案和网上的内容,删除了以下内容:
protected $dontReport = [
//
];
protected $dontFlash = [
'password',
'password_confirmation',
];
I copy here all of Handler.php generated by laravel 7.5, may be useful for someone:
我在这里复制了 laravel 7.5 生成的所有 Handler.php,可能对某人有用:
<?php
namespace App\Exceptions;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Throwable;
class Handler extends ExceptionHandler
{
/**
* A list of the exception types that are not reported.
*
* @var array
*/
protected $dontReport = [
//
];
/**
* A list of the inputs that are never flashed for validation exceptions.
*
* @var array
*/
protected $dontFlash = [
'password',
'password_confirmation',
];
/**
* Report or log an exception.
*
* @param \Throwable $exception
* @return void
*
* @throws \Exception
*/
public function report(Throwable $exception)
{
parent::report($exception);
}
/**
* Render an exception into an HTTP response.
*
* @param \Illuminate\Http\Request $request
* @param \Throwable $exception
* @return \Symfony\Component\HttpFoundation\Response
*
* @throws \Throwable
*/
public function render($request, Throwable $exception)
{
return parent::render($request, $exception);
}
}
}