简体   繁体   English

作曲家安装不兼容的 package

[英]Composer installing incompatible package

I have a composer.json file that includes the following:我有一个 composer.json 文件,其中包括以下内容:

"require": {
    "php": "~7.3.0",
    "ext-imagick": "*",
    "ext-apcu": "*",
    "ext-json": "*",
    "ext-blackfire": "*",
    "doctrine/doctrine-migrations-bundle": "^1.3",

The later use of --ignore-platform-reqs relates to the docker image not having those extensions, but the Heroku environment does.稍后使用--ignore-platform-reqs reqs 与没有这些扩展名的 docker 映像有关,但 Heroku 环境有。

The latter is requiring a package, which requires another package.后者需要一个 package,这需要另一个 package。

$ composer why ocramius/package-versions
doctrine/orm            v2.7.2  requires  ocramius/package-versions (^1.2)
ocramius/proxy-manager  2.8.0   requires  ocramius/package-versions (^1.8.0)

$ composer why ocramius/proxy-manager
doctrine/migrations  v1.8.1  requires  ocramius/proxy-manager (^1.0|^2.0)

This is installing code that uses PHP 7.4's property type declarations.这是使用 PHP 7.4 的属性类型声明的安装代码。 This throws a big ugly error in PHP 7.3.这会在 PHP 7.3 中引发一个严重的错误。

$ php -d memory_limit=-1 composer.phar update --ignore-platform-reqs
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 195 installs, 0 updates, 0 removals
  - Installing ocramius/package-versions (1.8.0): Loading from cache

Parse error: syntax error, unexpected 'string' (T_STRING), expecting function (T_FUNCTION) or const (T_CONST) in 
             /var/www/project/vendor/ocramius/package-versions/src/PackageVersions/Installer.php
             on line 33

Why am I always getting this version of ocramius/package-versions and how to do I prevent this error (and that package version) from happening?为什么我总是得到这个版本的ocramius/package-versions以及如何防止这个错误(以及那个 package 版本)发生?

The solution for me was to remove --ignore-platform-reqs .我的解决方案是删除--ignore-platform-reqs For any forward-leaning packages (any Ocramius package, for instance), this will either fail hard like this did, or you'll have several strange bugs you can't seem to track down the cause of.对于任何具有前瞻性的软件包(例如,任何 Ocramius package),这要么会像这样严重失败,要么你会遇到一些你似乎无法找到原因的奇怪错误。

What --ignore-platform-reqs does is it switches off the checks Composer makes to ensure that only packages compatible with the environment works. --ignore-platform-reqs所做的是关闭 Composer 所做的检查,以确保只有与环境兼容的软件包才能工作。 In this case, the offending package had a recent update to use PHP 7.4, and happened to use the new property type declarations in the Composer installer.在这种情况下,有问题的 package 最近更新为使用 PHP 7.4,并且碰巧在 Composer 安装程序中使用了新的属性类型声明。

I had been battling several other weirdnesses (like the Doctrine's Entity Manager failing randomly, another Ocramius-related package), which all went away by removing the flag when I ran Composer.我一直在与其他几个奇怪的问题作斗争(比如 Doctrine 的实体管理器随机失败,另一个与 Ocramius 相关的包),当我运行 Composer 时,所有这些都通过删除标志而消失了。 Whatever the reason I needed it years ago, I no longer do.不管几年前我需要它的原因是什么,我不再需要它了。

If you feel you need it, check out config.platform which seems to allow you to lie to Composer, or work to remove needing that flag altogether (why-ever you think you need it, get over it if possible).如果您觉得需要它,请查看似乎允许您对 Composer 撒谎的config.platform ,或者努力完全删除需要该标志(无论您为什么认为需要它,如果可能,请克服它)。

Lets you fake platform packages (PHP and extensions) so that you can emulate a production env or define your target platform in the config.允许您伪造平台包(PHP 和扩展),以便您可以模拟生产env或在配置中定义目标平台。 Example: {"php": "7.0.3", "ext-something": "4.0.3"} .示例: {"php": "7.0.3", "ext-something": "4.0.3"}

https://getcomposer.org/doc/06-config.md#platform https://getcomposer.org/doc/06-config.md#platform

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM