ChatGPT解决这个技术问题 Extra ChatGPT

Composer throws [ReflectionException] Class Fxp\Composer\AssetPlugin\Repository\NpmRepository does not exist

I installed the latest version (1.0.0. stable) of composer and in my Yii2 project I typed this:

php composer.phar update

It gives me this error:

[ReflectionException] Class Fxp\Composer\AssetPlugin\Repository\NpmRepository does not exist

[ErrorException] Declaration of Fxp\Composer\AssetPlugin\Repository\AbstractAssetsRepository::whatProvides() should be compatible with Composer\Repository\ComposerRepository::whatProvides(Composer\DependencyResolver\Pool $pool, $name, $bypassFilters = false)

Can someone help me how to fix this?

Here's my composer.json

{
    "name": "yiisoft/yii2-app-advanced",
    "description": "Yii 2 Advanced Project Template",
    "keywords": ["yii2", "framework", "advanced", "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.6",
        "yiisoft/yii2-bootstrap": "*",
        "yiisoft/yii2-swiftmailer": "*",
        "kartik-v/yii2-widget-fileinput": "@dev",
        "golonka/bbcodeparser": "^2.2"
    },
    "require-dev": {
        "yiisoft/yii2-codeception": "*",
        "yiisoft/yii2-debug": "*",
        "yiisoft/yii2-gii": "*",
        "yiisoft/yii2-faker": "*"
    },
    "config": {
        "process-timeout": 1800
    },
    "extra": {
        "asset-installer-paths": {
            "npm-asset-library": "vendor/npm",
            "bower-asset-library": "vendor/bower"
        }
    }
}
can you show us your composer.json?
@Federico there it is

s
sanmai

About nine days ago (around end of March, 2016), Composer\Repository\ComposerRepository::whatProvides api changed. (#2668) So, if you have installed fxp/composer-asset-plugin globally, you should update it. You can do that with:

php composer.phar global update fxp/composer-asset-plugin --no-plugins

Unfortunatelly, this command ends with the same error. Solved by removing ~/.composer directory and reinstalling fxp/composer-asset-plugin.
thanks for the feedback, I've added --no-plugins option to the answer.
Did not help. After a second call I get 'Nothing to install or update'. Then update will create the same errors agains. Any further ideas?
Working like a charm. Thx
Still I have the same problem
r
robsch

Try this one if update doesn't work.

composer global require fxp/composer-asset-plugin --no-plugins

this fixed mine. Thanks!
A
Alexander O'Mara

I ended up resolving the issue by removing the fxp directory from the .composer directory. On my setup, this does the trick:

rm -rf ~/.composer/vendor/fxp

Now when something needs it, it can just re-download the updated plugin.


For those using Windows: C:\Users\\AppData\Roaming\Composer\vendor
T
Tom Jowitt

Try to edit your global composer.json by running:

vi ~/.composer/composer.json then make sure you have this line on it:

{
    "require": {
        "fxp/composer-asset-plugin": "1.1.*"
    }
}

the above answers did not work for me because the version of my fxp/composer-asset-plugin was like 1.1-beta04, when I changed it to "1.1.8" and run updating command:

php /usr/bin/composer global update fxp/composer-asset-plugin --no-plugins

It fixed the problem. but without editing my global composer.json, it was giving me this error:

Your requirements could not be resolved to an installable set of packages. Problem 1 - Installation request for fxp/composer-asset-plugin 1.0.0-beta3 -> satisfiable by fxp/composer-asset-plugin[v1.0.0-beta3]. - fxp/composer-asset-plugin v1.0.0-beta3 requires composer-plugin-api 1.0.0 -> no matching package found. Potential causes: - A typo in the package name - The package is not available in a stable-enough version according to your minimum-stability setting see https://getcomposer.org/doc/04-schema.md#minimum-stability for more details. Read https://getcomposer.org/doc/articles/troubleshooting.md for further common problems.


T
Tom Jowitt

In my case project on Yii2

$ composer

  [ReflectionException]
  Class Fxp\Composer\AssetPlugin\Repository\NpmRepository does not exist


  [ErrorException]
  Declaration of Fxp\Composer\AssetPlugin\Repository\AbstractAssetsRepository
  ::whatProvides() should be compatible with Composer\Repository\ComposerRepo
  sitory::whatProvides(Composer\DependencyResolver\Pool $pool, $name, $bypass
  Filters = false)

Yii2, in folder vendor/fxp you need to replace the folder composer-asset-plugin or delete it.


I
Ivo Pereira

If none of the other solutions have worked for you, please try AssetPackagist as an alternative.

Add the packages bower-asset/bootstrap and npm-asset/jquery to composer.json like the following: "require": { "bower-asset/bootstrap": "^3.3", "npm-asset/jquery": "^2.2" } Add a repositories block (if you still don't have one, if you do, just append to it) with the following content: "repositories": [ { "type": "composer", "url": "https://asset-packagist.org" } ] Run composer install (or composer update) Considering that asset-packagist installs assets in a different directory, add the following lines to your application config (usually called as web.php): $config = [ 'aliases' => [ '@bower' => '@vendor/bower-asset', '@npm' => '@vendor/npm-asset', ], ];

These instructions may change over time. They have been copied from the repo website so they could last in time just in case something happens to the website. I am not the author of the repo but I really appreciate the effort made into it. Please check https://asset-packagist.org/site/about to know more about the project.

If you are struggling with composer, here you have some useful commands:

composer clear-cache - Clear composer related caches

composer install -vvv - Add the parameter "vvv" to show installation process related output (useful to debug)

composer global show - Useful to check if you already have fxp/composer-asset-plugin installed. In my case, it already was, however it was not being detected as a dependency, and the solution I described earlier worked flawless to me - hope it does work for you too!


M
Madalin

You can make a permanent fix by requiring it at global level and then it's solved for every other project. But then make sure you give the tip to all your team members.

Best is to add this at project scope and it solves to everybody that way.

So:

composer require fxp/composer-asset-plugin


关注公众号,不定期副业成功案例分享
Follow WeChat

Success story sharing

Want to stay one step ahead of the latest teleworks?

Subscribe Now