Jitendra
Jitendra

Reputation: 578

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

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.

Upvotes: 6

Views: 5962

Answers (3)

Laerte
Laerte

Reputation: 7083

I had this same error when migrating an old project from Laravel 5.1 to 5.2. The solution was running:

$ rm -Rf bootstrap/cache/*

This will clear cache manually and php artisan clear-compiled is gonna work again.

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

Upvotes: 0

Yoga
Yoga

Reputation: 1196

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

Upvotes: 1

James
James

Reputation: 16349

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

Upvotes: 14

Related Questions