Command “clear-compiled” is not defined. Laravel 5.2

你说的曾经没有我的故事 提交于 2020-01-03 15:24:46

问题


I am trying to download Laravel HTML dependencies with Composer.

composer.json is here:

"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"
    },

And when I run composer update or php composer update, the terminal log is:

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>]...

What is missing? Please help.


回答1:


You can get around this by using composer update --no-scripts which runs the update command from composer without the executing the scripts defined in the composer.json file.

As part of running composer update a script is executed which runs php artisan clear-compiled - effectively the update works as normal, just without compiled files being cleared.

There's a couple of blog posts on other work arounds: http://jianjye.com/fix-command-clear-compiled-not-defined-error-upgrading-laravel-5-2/ and an issue logged https://github.com/laravel/framework/issues/9678




回答2:


The current answer here does not satisfy someone who wants to perform clear-compiled action. Here is the solution with an equivalent script, (taken from https://github.com/laravel/framework/issues/9678)

Create a script at the laravel's root folder called clear-compiled with the contents:

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

Then in composer.json, change php artisan clear-compiled to php clear-compiled:

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


来源:https://stackoverflow.com/questions/36514499/command-clear-compiled-is-not-defined-laravel-5-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!