未定义命令“明编译”.拉拉维尔 5.2.


Command "clear-compiled" is not defined. Laravel 5.2

我正在尝试使用Composer下载Laravel HTML依赖项。

composer.json在这里:

"name": "laravel/laravel",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "license": "MIT",
    "type": "project",
    "require": {
        "php": ">=5.5.9",
        "laravel/framework": "5.2.*",
        "illuminate/html": "5.2"
    },

当我运行composer updatephp composer update时,终端日志是:

E:'xampp'htdocs'lara-test>composer update
> php artisan clear-compiled
  [InvalidArgumentException]
  Command "clear-compiled" is not defined.
Script php artisan clear-compiled handling the pre-update-cmd event returned with an error
  [RuntimeException]
  Error Output:
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] [--pre
fer-lowest] [-i|--interactive] [--] [<packages>]...

缺少什么?请帮忙。

您可以使用composer update --no-scripts来解决此问题,该 从

作曲家运行 update 命令,而无需执行composer.json文件中定义的脚本。

作为运行composer update的一部分,将执行php artisan clear-compiled运行的脚本 - 实际上更新正常工作,只是没有清除已编译的文件。

有几篇关于其他解决方法的博客文章:http://jianjye.com/fix-command-clear-compiled-not-defined-error-upgrading-laravel-5-2/和记录的问题 https://github.com/laravel/framework/issues/9678

> 这里的当前答案并不能满足想要执行clear-compiled动作的人。这是具有等效脚本的解决方案(取自 https://github.com/laravel/framework/issues/9678(

在 laravel 的根文件夹中创建一个名为 clear-compiled 的脚本,其中包含以下内容:

#!/usr/bin/env php
<?php
foreach (glob(__DIR__ . '/bootstrap/cache/*.*') as $file) {
    @unlink($file);
}
echo 'Cleared compiled directory.';
exit();

然后在composer.json中,将php artisan clear-compiled更改为php clear-compiled

"scripts": {
    "pre-install-cmd": [
        "php clear-compiled"
    ],
    "post-install-cmd": [
        "php clear-compiled"
    ]
},

将旧项目从 Laravel 5.1 迁移到 5.2 时,我遇到了同样的错误。解决方案正在运行:

$ rm -Rf bootstrap/cache/*

这将手动清除缓存,php artisan clear-compiled将再次工作。

参考: https://jianjye.com/p/fix-command-clear-compiled-not-defined-error-laravel/