Composer 错误:无法解析版本约束 >=~2

Posted

技术标签:

【中文标题】Composer 错误:无法解析版本约束 >=~2【英文标题】:Composer error: Could not parse version constraint >=~2 【发布时间】:2017-07-16 14:16:20 【问题描述】:

朋友们,在尝试运行时

作曲家更新

出现如下错误:

C:\wamp\www\mysystem>composer update 加载 composer 存储库 带包信息更新依赖(包括require-dev)

[UnexpectedValueException] 无法解析版本约束

=~2: 无效的版本字符串“~2”

更新 [--prefer-source] [--prefer-dist] [--dry-run] [--dev] [--no-dev] [--lock] [--no-custom-installers] [--no-autoloader] [--no-scripts] [--no-progress] [--no -suggest] [--with-dependencies] [-v|vv|vvv|--verbose] [-o|--optimize-autoloader] [-a|--classmap-authoritative] [--apcu-autoloader] [--ignore-platform-reqs] [--p 参考稳定] [--prefer-lowest] [-i|--interactive] [--root-reqs] [--] [

]...

这是我的 composer.json 文件:


    "license": "BSD-3-Clause",
    "minimum-stability": "stable",
    "require": 
        "php": ">=5.4.0",
        "yiisoft/yii2": ">=2.0.5",
        "yiisoft/yii2-bootstrap": "*",
        "yiisoft/yii2-swiftmailer": "*",
        "fxp/composer-asset-plugin": "~1.1.1",       
        "trntv/yii2-datetime-widget": "*",
        "miloschuman/yii2-highcharts-widget": "dev-master",
        "kartik-v/yii2-money": "*",
        "kartik-v/yii2-slider": "*",
        "kartik-v/yii2-widget-datepicker": "@dev",
        "kartik-v/yii2-field-range": "*",
        "kartik-v/yii2-widget-colorinput": "*",
        "kartik-v/yii2-widget-sidenav": "@dev",
        "kartik-v/yii2-export": "@dev",
        "kartik-v/yii2-grid": "@dev",
        "yiidoc/yii2-redactor": "*",
        "tugmaks/yii2-google-maps": "dev-master",
        "yiisoft/yii2-imagine": "^2.0",
        "karpoff/yii2-crop-image-upload": "*",
        "cyneek/yii2-menu": "dev-master",
        "bupy7/yii2-widget-cropbox": "*",
        "philippfrenzel/yii2fullcalendar": "*",
        "kartik-v/yii2-widget-touchspin": "*"
    ,
    "require-dev": 
        "yiisoft/yii2-debug": "*",
        "yiisoft/yii2-gii": "*",
        "yiisoft/yii2-faker": "*"
    ,
    "config": 
        "process-timeout": 1800
    ,
    "scripts": 
        "post-create-project-cmd": [
            "yii\\composer\\Installer::postCreateProject"
        ]
    ,
    "extra": 
        "yii\\composer\\Installer::postCreateProject": 
            "setPermission": [
                
                    "runtime": "0777",
                    "web/assets": "0777",
                    "yii": "0755"
                
            ],
            "generateCookieValidationKey": [
                "config/web.php"
            ]
        ,
        "asset-installer-paths": 
            "npm-asset-library": "vendor/npm",
            "bower-asset-library": "vendor/bower"
        
    

我在 w7 和 ubuntu 上试过

【问题讨论】:

【参考方案1】:

尝试设置旧版本fxp/composer-asset-plugin:

composer global require "fxp/composer-asset-plugin:1.0.1"

或安装最新的:

composer global require "fxp/composer-asset-plugin:dev-master"

【讨论】:

以上是关于Composer 错误:无法解析版本约束 >=~2的主要内容,如果未能解决你的问题,请参考以下文章

捆绑包 XYZ 无法解析。原因:缺少约束:Import-Package:ABC;无头 RCP 独立版本中的 version="1.0.0" 错误

Laravel 中的 Composer 更新错误“需求无法解析为一组可安装的软件包”[重复]

Composer Laravel 安装错误:您的需求无法解析为一组可安装的软件包

如何验证 Composer 版本约束支持所需的版本?

composer requireIllumination/support 会给出一个错误,例如“您的需求无法解析为一组可安装的软件包”。

您的要求无法解析为一组可安装的软件包(Composer 更新)