安装包时出错“安装失败,正在将 ./composer.json 和 ./composer.lock 还原为其原始内容。”

error installing a package " Installation failed, reverting ./composer.json and ./composer.lock to their original content. "

我正在尝试在我的 laravel 包上安装 spatie/sitemap 包,但我一直收到此错误,我不知道是什么问题:

无法将您的要求解析为一组可安装的软件包。

问题 1

    - spatie/crawler[5.0.2, ..., v5.x-dev] require guzzlehttp/psr7 ^1.4 -> found guzzlehttp/psr7[1.4.0, ..., 1.x-dev] but the package is fixed to 2.0.0 
(lock file version) by a partial update and that version does not match. Make sure you list it as an argument for the update command.
    - spatie/crawler[5.0.0, ..., 5.0.1] require php ^7.4 -> your php version (8.0.1) does not satisfy that requirement.
    - spatie/crawler 7.0.0 requires guzzlehttp/psr7 ^1.8 -> found guzzlehttp/psr7[1.8.0, 1.8.1, 1.8.2, 1.x-dev] but the package is fixed to 2.0.0 (lock 
file version) by a partial update and that version does not match. Make sure you list it as an argument for the update command.
    - spatie/laravel-sitemap 6.0.4 requires spatie/crawler ^5.0 || ^7.0 -> satisfiable by spatie/crawler[5.0.0, 5.0.1, 5.0.2, v5.x-dev, 7.0.0].
    - Root composer.json requires spatie/laravel-sitemap 6.0.4 -> satisfiable by spatie/laravel-sitemap[6.0.4].

Use the option --with-all-dependencies (-W) to allow upgrades, downgrades and removals for packages currently locked to specific versions.

Installation failed, reverting ./composer.json and ./composer.lock to their original content.

我试图指定软件包的版本并使用了最新的 6.0.4,但它也没有用,我不知道该怎么做!!请帮忙。

更新

这是 composer.json :

{
"name": "laravel/laravel",
"type": "project",
"description": "The Laravel Framework.",
"keywords": [
    "framework",
    "laravel"
],
"license": "MIT",
"require": {
    "php": "^8.0",
    "alexpechkarev/google-maps": "^8.0",
    "appstract/laravel-opcache": "^4.0",
    "cviebrock/eloquent-sluggable": "^8.0",
    "fideloper/proxy": "^4.4",
    "fruitcake/laravel-cors": "^2.0",
    "intervention/image": "^2.5",
    "laravel/framework": "^8.12",
    "laravel/tinker": "^2.6",
    "mews/captcha": "^3.2",
    "nesbot/carbon": "^2.48",
    "simplesoftwareio/simple-qrcode": "~4"
},
"require-dev": {
    "facade/ignition": "^2.5",
    "fakerphp/faker": "^1.9.1",
    "laravel/sail": "^1.0.1",
    "mockery/mockery": "^1.4.2",
    "nunomaduro/collision": "^5.0",
    "phpunit/phpunit": "^9.3.3"
},
"config": {
    "optimize-autoloader": true,
    "preferred-install": "dist",
    "sort-packages": true
},
"extra": {
    "laravel": {
        "dont-discover": []
    }
},
"autoload": {
    "psr-4": {
        "App\": "app/",
        "Database\Factories\": "database/factories/",
        "Database\Seeders\": "database/seeders/"
    }
},
"autoload-dev": {
    "psr-4": {
        "Tests\": "tests/"
    }
},
"minimum-stability": "dev",
"prefer-stable": true,
"scripts": {
    "post-autoload-dump": [
        "Illuminate\Foundation\ComposerScripts::postAutoloadDump",
        "@php artisan package:discover --ansi"
    ],
    "post-root-package-install": [
        "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
    ],
    "post-create-project-cmd": [
        "@php artisan key:generate --ansi"
    ]
}

}

spatie/sitemap 需要 spatie/crawler,而这个(即使在最新版本中)需要 guzzlehttp/psr7 的 v1。这并不奇怪,因为该软件包的 v2 只有三个星期,而且 spatie/crawler 从那时起就没有更新过。

要找到解决方案,请阅读错误消息:

Use the option --with-all-dependencies (-W) to allow upgrades, downgrades and removals for packages currently locked to specific versions.

Composer 可能会帮助您解决依赖性问题,但前提是您使用 -W 标志告诉它这样做。


如果这不起作用:您可能需要检查哪个其他软件包需要 v2 中的 guzzlehttp/psr7。这是一个非常新的版本,composer why-not guzzlehttp/psr7 1.8.2 可能会列出任何禁止降级该软件包的软件包。如果这确实列出了任何冲突的包,您需要进一步检查哪个需要降级

我通过安装和启用 php exif 让它工作,首先我通过 composer 安装了一个 php exif 包,然后我从 php.ini 启用它并且它工作得很好。

我在安装 Google 的 apiclient 时遇到了类似的问题,我通过添加以下选项解决了这个问题:

composer require google/apiclient:^2.10 --with-all-dependencies