Search code examples
laravelcomposer-phpphp-8

php 8.2 + laravel 9 failed with composer error that cron-expression does not match the constraint


I am updating laravel to use php 8.2, according to laravel document here, using "laravel/framework": "^9.43" should be enough.

php 8.2 & larvel 9

My composer.json are the following,

"require": {
    "php": "^8.2",
    "clue/socket-raw": "^1.3",
    "fideloper/proxy": "^4.4",
    "fruitcake/laravel-cors": "^2.0",
    "gregwar/captcha": "1.*",
    "guzzlehttp/guzzle": "^7.0.1",
    "itsgoingd/clockwork": "^5.1",
    "jacobcyl/ali-oss-storage": "^2.0",
    "james-heinrich/getid3": "^1.9",
    "laravel/framework": "^9.43",
    "laravel/horizon": "^5.7",
    "laravel/tinker": "^2.5",
    "php-curl-class/php-curl-class": "^8.6"
},

But when running composer install --no-scripts --no-autoloader --no-dev (I don't use composer.lock here), composer complained,

laravel/framework[v9.43.0, ..., 9.x-dev] require dragonmantank/cron-expression ^3.3.2 -> found dragonmantank/cron-expression[dev-set-up-semaphore, dev-update-v3-php8, dev-master, dev-issue/35-fix-and-or-problem, dev-allow-phpstan-failures, v1.0.0, ..., v1.2.1, v2.0.0, ..., v2.3.1.x-dev, v3.0.0, ..., v3.3.1] but it does not match the constraint.

I know laravel/framework 9 requires cron-expression ^3.3.2 as https://packagist.org/packages/laravel/framework said. But I can't figure out which other package requires a different version of cron-expression. I search the old composer.lock (which I don't use when install) I find multi-mention of dev-master, but no [dev-set-up-semaphore, dev-update-v3-php8, dev-issue/35-fix-and-or-problem, dev-allow-phpstan-failures]

Please check the following build log

composer error

How do I find that package ? BTW, php 8.1.7 + "laravel/framework" 8 works fine.

--- update ---

I find the reason why composer complains.

I have "require-dev" in my composer and all packages in it use the latest versions! I also check https://packagist.org/ to make sure they all say they support ^8.0. Besides, my command is composer install --no-scripts --no-autoloader --no-dev, no-dev !

So I didn't expect "require-dev" will cause problem. But only after I remove the "require-dev" did composer run successfully!

Apparently one of those packages do not support php 8.2 yet.

"require-dev": {
    "facade/ignition": "^2.17",
    "fakerphp/faker": "^1.21.0",
    "laravel/sail": "^1.18.1",
    "mockery/mockery": "^1.5.1",
    "nunomaduro/collision": "^6.4",
    "phpunit/phpunit": "^9.5.28"
}

After removing "facade/ignition" from "require-dev", composer finally works!

As for why does "facade/ignition" cause the problem and what is the solution for it, please refer to @NicoHaase's answer and my discussion with him.


Solution

  • "Apparently one of those packages do not support php 8.2 yet." - no, that's not the cause. Ignition does not support Laravel v9, as written in their readme:

    If you're on Laravel 8 or above, you can switch to spatie/laravel-ignition, which is a drop-in replacement. Replace facade/ignition with "spatie/laravel-ignition": "^1.0" in your application's composer.json file.

    Going forward, we'll only add security fixes to facade/ignition and highly encourage you to switch to spatie/laravel-ignition.