yii2 composer update fatal error

2019-03-24 08:57发布

问题:

When I update my composer to add yii2-solr extension to my project, I encounter with an error like below:

The "yiisoft/yii2-composer" plugin requires composer-plugin-api 1.0.0, this *WILL* break in the future and it should be fixed ASAP (require ^1.0 for example).
The "fxp/composer-asset-plugin" plugin requires composer-plugin-api 1.0.0, this *WILL* break in the future and it should be fixed ASAP (require ^1.0 for example).

PHP Fatal error:  Call to undefined method Fxp\Composer\AssetPlugin\Package\Version\VersionParser::parseLinks() in /root/.composer/vendor/fxp/composer-asset-plugin/Repository/VcsPackageFilter.php on line 272

Fatal error: Call to undefined method Fxp\Composer\AssetPlugin\Package\Version\VersionParser::parseLinks() in /root/.composer/vendor/fxp/composer-asset-plugin/Repository/VcsPackageFilter.php on line 272

before that I've ran composer self-updatebut still not work and when I want to run

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

again the above error shown. This is my composer.json file content:

{
"name": "yiisoft/yii2-app-basic",
"description": "Yii 2 Basic Project Template",
"keywords": ["yii2", "framework", "basic", "project template"],
"homepage": "http://www.yiiframework.com/",
"type": "project",
"license": "BSD-3-Clause",
"support": {
    "issues": "https://github.com/yiisoft/yii2/issues?state=open",
    "forum": "http://www.yiiframework.com/forum/",
    "wiki": "http://www.yiiframework.com/wiki/",
    "irc": "irc://irc.freenode.net/yii",
    "source": "https://github.com/yiisoft/yii2"
},
"minimum-stability": "stable",
"require": {
    "php": ">=5.4.0",       
    "yiisoft/yii2": ">=2.0.5",
    "yiisoft/yii2-bootstrap": "*",
    "yiisoft/yii2-swiftmailer": "*",
    "filsh/yii2-oauth2-server": "*",
    "johnitvn/yii2-rbac-plus": "*",
    "yiisoft/yii2-sphinx": "^2.0",
    "yiisoft/yii2-solr": "*"
},
"require-dev": {
    "yiisoft/yii2-codeception": "*",
    "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"
    }
}

}

How can I fix this error? Thanks.

回答1:

1) Remove old version of Composer Asset Plugin:

composer global remove "fxp/composer-asset-plugin"

2) Install newer version. Recommended version for installation is now (by the moment of writing this) 1.1.1 (see official docs).

composer global require "fxp/composer-asset-plugin:~1.1.1"

I'd even recommend to use:

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

3) Run composer install in your project folder. In case of errors, delete vendor folder contents and composer.lock file and run composer install again.



回答2:

If arogachev's answer doesn't exactly work for you, here is a quick fix.

  1. Manually delete the vendor folder in your global composer installation. The folder to delete for eg. on ubuntu : /home/user/.composer/vendor
  2. Install the newer version of the plugin

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

That should be all. You will get all your files back and you can continue



回答3:

Bower-Asset skip way:

You can require yidas/yii2-composer-bower-skip before yiisoft/yii2 in composer.json file:

"require": {
    "php": ">=5.4.0",      
    "yidas/yii2-composer-bower-skip": "~2.0.0", 
    "yiisoft/yii2": ">=2.0.5",
    "yiisoft/yii2-bootstrap": "*",
    ...

Then run composer update.

This case is for that you don't need the update for Bower.

See https://github.com/yidas/yii2-composer-bower-skip