作曲家无法加载包无效的版本字符串

Posted

技术标签:

【中文标题】作曲家无法加载包无效的版本字符串【英文标题】:composer could not load package Invalid version string 【发布时间】:2020-12-27 06:25:49 【问题描述】:

我遇到范围情况,当我尝试在本地安装一些捆绑包时遇到错误,但是当我尝试在测试服务器中安装相同的捆绑包时,所有安装都没有错误。我使用 docker-compose 并在图像中安装包。 docker-copose 和其他 docker 文件,所有依赖项完全相同,都在 git 中。

composer require league/flysystem-bundle

在本地我也遇到过这种情况

使用 dev-master 版本进行联赛/flysystem-bundle ./composer.json 已更新 使用包信息加载作曲家存储库 更新依赖项(包括 require-dev) 将“symfony/symfony”中列出的软件包限制为“5.0.*”

安装失败,正在将 ./composer.json 还原为其原始内容。

  [RuntimeException]                                                           
  Could not load package ezsystems/ezplatform in http://repo.packagist.org: [  
  UnexpectedValueException] Could not parse version constraint dev-load-varni  
  sh-only-when-used as ^2.0@dev: Invalid version string "^2.0@dev"             
                                                                               

                                                                               
  [UnexpectedValueException]                                                   
  Could not parse version constraint dev-load-varnish-only-when-used as ^2.0@  
  dev: Invalid version string "^2.0@dev" 

本地作曲家版本作曲家版本1.10.11 2020-09-08 16:53:44

和测试服务器

/var/www/symfony # composer require league/flysystem-bundle
Using version dev-master for league/flysystem-bundle
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Restricting packages listed in "symfony/symfony" to "5.0.*"

Prefetching 3 packages ???? ????
  - Downloading (100%)

Package operations: 3 installs, 0 updates, 0 removals
  - Installing league/mime-type-detection (1.4.0): Loading from cache
  - Installing league/flysystem (1.x-dev 53f16fd): Loading from cache
  - Installing league/flysystem-bundle (dev-master 525845a): Loading from cache
Package easycorp/easy-log-handler is abandoned, you should avoid using it. No replacement was suggested.
Package zendframework/zend-code is abandoned, you should avoid using it. Use laminas/laminas-code instead.
Package zendframework/zend-eventmanager is abandoned, you should avoid using it. Use laminas/laminas-eventmanager instead.
Writing lock file
Generating autoload files
20 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
Symfony operations: 1 recipe (c67222ac592a52b7dec1c2cd56763685)
  -  WARNING  league/flysystem-bundle (>=1.0): From github.com/symfony/recipes-contrib:master
    The recipe for this package comes from the "contrib" repository, which is open to community contributions.
    Review the recipe at https://github.com/symfony/recipes-contrib/tree/master/league/flysystem-bundle/1.0

    Do you want to execute this recipe?
    [y] Yes
    [n] No
    [a] Yes for all packages, only for the current installation session
    [p] Yes permanently, never ask again for this project
    (defaults to n): 
ocramius/package-versions:  Generating version class...
ocramius/package-versions: ...done generating version class
Executing script cache:clear [OK]
Executing script assets:install public [OK]

测试服务器 composer version Composer 版本 1.10.10 2020-08-03 11:35:19

我的码头文件

FROM alpine:edge

LABEL maintainer="Vincent Composieux <vincent.composieux@gmail.com>"

RUN apk add --update --no-cache \
    coreutils \
    yarn \
    php7-fpm \
    php7-apcu \
    php7-ctype \
    php7-curl \
    php7-dom \
    php7-gd \
    php7-iconv \
    php7-imagick \
    php7-json \
    php7-intl \
    php7-mcrypt \
    php7-fileinfo\
    php7-mbstring \
    php7-opcache \
    php7-openssl \
    php7-pdo \
    php7-pdo_mysql \
    php7-mysqli \
    php7-pdo_pgsql \
    php7-pgsql \
    php7-xml \
    php7-zlib \
    php7-phar \
    php7-tokenizer \
    php7-session \
    php7-simplexml \
    php7-xdebug \
    php7-zip \
    php7-xmlwriter \
    make \
    curl \
    zlib-dev \
    libxml2-dev \
    rabbitmq-c-dev \
    oniguruma-dev \
    php7-pecl-amqp \
    php7-amqp \
    php7-redis

RUN apk add --no-cache --repository=http://dl-cdn.alpinelinux.org/alpine/edge/testing/ php7-pecl-mongodb

RUN echo "$(curl -sS https://composer.github.io/installer.sig) -" > composer-setup.php.sig \
        && curl -sS https://getcomposer.org/installer | tee composer-setup.php | sha384sum -c composer-setup.php.sig \
        && php composer-setup.php && rm composer-setup.php* \
        && chmod +x composer.phar && mv composer.phar /usr/bin/composer

COPY symfony.ini /etc/php7/conf.d/
COPY symfony.ini /etc/php7/cli/conf.d/
COPY xdebug.ini  /etc/php7/conf.d/

COPY symfony.pool.conf /etc/php7/php-fpm.d/

CMD ["php-fpm7", "-F"]

WORKDIR /var/www/symfony
EXPOSE 9001

为什么我同时面对不同版本的作曲家。 Composer 以相同的方式安装,由相同的 Dockerfile 安装。如何解决这个问题? 我不相信,怎么可能,这个问题在使用docker结构时不应该出现..?

【问题讨论】:

这能回答你的问题吗? Why am I not allowed to install my dependencies with composer? 【参考方案1】:

现在您可以将您的作曲家版本更新为1.10.12

在这个版本中你没有这个错误。

【讨论】:

【参考方案2】:

确认来自 composer 1.10.11 的错误。您应该使用 composer v1.10.10。

composer self-update 1.10.10

您可以使用self-update来降级composer版本

【讨论】:

【参考方案3】:

看起来 composer 1.10.11 坏了。您可以像这样切换到 1.10.10:

composer-setup.php --version=1.10.10

【讨论】:

你说得对。问题出在新作曲家版本 1.10.11 上。我减少到 1.10.10 并安装了 lib

以上是关于作曲家无法加载包无效的版本字符串的主要内容,如果未能解决你的问题,请参考以下文章

作曲家转储自动加载无法识别的命令

作曲家自动加载器 psr-0 命名空间

当供应商在 Symfony 2.1 中不受作曲家管理时,在哪里注册自动加载?

Composer 更新:您的要求无法解决为一组可安装的软件包

从单一存储库加载一个特定的作曲家包

由于版本冲突,无法加载某个程序集