Heroku 部署失败,在任何版本中都找不到请求的包 composer-plugin-api

标签 heroku composer-php laravel-8 web-deployment

-----> Building on the Heroku-20 stack
-----> Using buildpack: heroku/php
-----> PHP app detected
-----> Bootstrapping...
-----> Installing platform packages...
 !     ERROR: Failed to install system packages!
 !     
 !     Your platform requirements (for runtimes and extensions) could
 !     not be resolved to an installable set of dependencies, or a
 !     platform package repository was unreachable.
 !     
 !     This usually means that you (or packages you are using) depend
 !     on a combination of PHP versions and/or extensions that are
 !     currently not available on Heroku.
 !     
 !     The following is the full output from the installation attempt:
 !     
 !     > You are using Composer 1 which is deprecated. You should upgrade to Composer 2, see https://blog.packagist.com/deprecating-composer-1-support/
 !     > Loading repositories with available runtimes and extensions
 !     > Updating dependencies
 !     > Your requirements could not be resolved to an installable set of packages.
 !     > 
 !     >   Problem 1
 !     >     - The requested package composer-plugin-api could not be found in any version, there may be a typo in the package name.
 !     > 
 !     
 !     For reference, the following runtimes are currently available:
 !     
 !     PHP:  8.1.1, 8.1.0, 8.0.14, 8.0.13, 8.0.12, 8.0.11, 8.0.10, 
 !     8.0.9, 8.0.8, 8.0.7, 8.0.6, 8.0.3, 8.0.2, 8.0.1, 8.0.0, 
 !     8.0.0RC4, 7.4.27, 7.4.26, 7.4.25, 7.4.24, 7.4.23, 7.4.22, 
 !     7.4.21, 7.4.20, 7.4.19, 7.4.16, 7.4.15, 7.4.14, 7.4.13, 
 !     7.4.12, 7.3.33, 7.3.32, 7.3.31, 7.3.30, 7.3.29, 7.3.28, 
 !     7.3.27, 7.3.26, 7.3.25, 7.3.24
 !     
 !     Please verify that all requirements for runtime versions in
 !     'composer.lock' are compatible with the list above, and ensure
 !     all required extensions are available for the desired runtimes.
 !     
 !     When choosing a PHP runtimes and extensions, please also ensure
 !     they are available on your app's stack (heroku-20), and select
 !     a different stack if needed after consulting the article below.
 !     
 !     For a list of supported runtimes & extensions on Heroku, please
 !     refer to: https://devcenter.heroku.com/articles/php-support
 !     Push rejected, failed to compile PHP app.
 !     Push failed

上面的 Coeds 是我在部署应用程序时遇到的错误,该应用程序在本地运行得很好,我不确定在部署过程中发生了什么。

composer.json

{
    "name": "laravel/laravel",
    "type": "project",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "license": "MIT",
    "require": {
        "php": "^8.1.1",
        "composer-plugin-api": "^2.2",
        "dcat/laravel-admin": "^1.7",
        "fruitcake/laravel-cors": "^2.0",
        "guzzlehttp/guzzle": "^7.0.1",
        "laravel/framework": "^8.75",
        "laravel/sanctum": "^2.11",
        "laravel/tinker": "^2.5"
    },
    "require-dev": {
        "facade/ignition": "^2.5",
        "fakerphp/faker": "^1.9.1",
        "laravel/sail": "^1.0.1",
        "mockery/mockery": "^1.4.4",
        "nunomaduro/collision": "^5.10",
        "phpunit/phpunit": "^9.5.10",
        "composer/composer": "^2.0"
    },
    "autoload": {
        "psr-4": {
            "App\\": "app/",
            "Database\\Factories\\": "database/factories/",
            "Database\\Seeders\\": "database/seeders/"
        }
    },
    "autoload-dev": {
        "psr-4": {
            "Tests\\": "tests/"
        }
    },
    "scripts": {
        "post-autoload-dump": [
            "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
            "@php artisan package:discover --ansi"
        ],
        "post-update-cmd": [
            "@php artisan vendor:publish --tag=laravel-assets --ansi --force"
        ],
        "post-root-package-install": [
            "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "@php artisan key:generate --ansi"
        ]
    },
    "extra": {
        "laravel": {
            "dont-discover": []
        }
    },
    "config": {
        "optimize-autoloader": true,
        "preferred-install": "dist",
        "sort-packages": true
    },
    "minimum-stability": "dev",
    "prefer-stable": true
}

错误 1

请求的包 composer-plugin-api 在任何版本中都找不到,包名可能有错别字。

错误 2

我使用的是 Composer 版本 2.2.1,为什么在部署期间显示我使用的是 Composer 1?

错误 3

composer.json 文件中,我已经要求 PHP 8.1.1,为什么它仍然说我没有使用正确的版本?

最佳答案

看起来您用于部署应用程序的 Heroku 服务器不支持本地使用的 composer 版本。 当您使用 heroku-20 时,请确保您使用 Composer 1.10.* 或 2.1.*

我的假设是您将 Composer 更新为 2.2.x,目前可能不受支持。您应该暂时降级到 Composer 2.1.14,然后再次运行 composer update

composer self-update --rollback
composer -v # Make sure the version is 2.1.*
composer update

关于Heroku 部署失败,在任何版本中都找不到请求的包 composer-plugin-api,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70495907/

相关文章:

heroku - 如何使用heroku设置环境变量?

linux - 类似 heroku 的 vps 部署工具

django - 为什么在Django设置中将debug设置为false会阻止Heroku应用程序在开发和生产中加载?

Laravel valet secure 不起作用,删除后 nginx 信息来自哪里?

php - Laravel - 使用不同 channel 存储每个用户的通知设置

php - Laravel 8 - 不支持的授权类型

heroku - 错误: Cannot find module 'webpack' when deploying to heroku

symfony - 将 PHPExcel 与 Composer 和 Symfony2.2 结合使用

windows - 从 Windows 转到 centOS 时 Composer 无法正常工作

php - 拉拉维尔 8 : Undefined variable when loading a Blade into another Blade