php Composer 抛出 [ReflectionException] Class Fxp\Composer\AssetPlugin\Repository\NpmRepository 不存在
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36437837/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Composer throws [ReflectionException] Class Fxp\Composer\AssetPlugin\Repository\NpmRepository does not exist
提问by Marko Mikuli?
I installed the latest version (1.0.0. stable) of composer and in my Yii2 project I typed this:
我安装了最新版本 (1.0.0. stable) 的 composer 并在我的 Yii2 项目中输入了以下内容:
php composer.phar update
php composer.phar update
It gives me this error:
它给了我这个错误:
[ReflectionException] Class Fxp\Composer\AssetPlugin\Repository\NpmRepository does not exist
[ReflectionException] Class Fxp\Composer\AssetPlugin\Repository\NpmRepository 不存在
[ErrorException] Declaration of Fxp\Composer\AssetPlugin\Repository\AbstractAssetsRepository::whatProvides() should be compatible with Composer\Repository\ComposerRepository::whatProvides(Composer\DependencyResolver\Pool $pool, $name, $bypassFilters = false)
[ErrorException] Fxp\Composer\AssetPlugin\Repository\AbstractAssetsRepository::whatProvides() 的声明应该与 Composer\Repository\ComposerRepository::whatProvides(Composer\DependencyResolver\Pool $pool, $name, $bypassFilters = false) 兼容
Can someone help me how to fix this?
有人可以帮我解决这个问题吗?
Here's my composer.json
这是我的 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"
}
}
}
回答by Federkun
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:
大约 9 天前(大约 2016 年 3 月底),Composer\Repository\ComposerRepository::whatProvides
api 发生了变化。( #2668) 因此,如果您已fxp/composer-asset-plugin
全局安装,则应更新它。你可以这样做:
php composer.phar global update fxp/composer-asset-plugin --no-plugins
回答by Javid Ahadov
Try this one if update doesn't work.
如果更新不起作用,请尝试此方法。
composer global require fxp/composer-asset-plugin --no-plugins
回答by 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:
我最终通过从fxp
目录中删除目录来解决这个问题.composer
。在我的设置中,这可以解决问题:
rm -rf ~/.composer/vendor/fxp
Now when something needs it, it can just re-download the updated plugin.
现在,当需要它时,它可以重新下载更新的插件。
回答by Mohammad Eghlima
Try to edit your global composer.json
by running:
尝试composer.json
通过运行来编辑您的全局:
vi ~/.composer/composer.json
then make sure you have this line on it:
vi ~/.composer/composer.json
然后确保你有这条线:
{
"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:
上述答案对我不起作用,因为我的版本fxp/composer-asset-plugin
就像1.1-beta04
,当我将其更改为"1.1.8"
并运行更新命令时:
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:
它解决了这个问题。但没有编辑我的 global composer.json
,它给了我这个错误:
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-stabilityfor more details.
Read https://getcomposer.org/doc/articles/troubleshooting.mdfor further common problems.
无法将您的要求解析为一组可安装的软件包。
问题 1 - fxp/composer-asset-plugin 1.0.0-beta3 的安装请求 -> fxp/composer-asset-plugin[v1.0.0-beta3] 可满足。- fxp/composer-asset-plugin v1.0.0-beta3 需要 composer-plugin-api 1.0.0 -> 找不到匹配的包。
可能的原因: -在包名称的错字-根据您的最低稳定性设定看到包不能在一个稳定的,足以版本https://getcomposer.org/doc/04-schema.md#minimum-stability为更多细节。
阅读https://getcomposer.org/doc/articles/troubleshooting.md了解更多常见问题。
回答by Isayevskiy_Sergey
In my case project on Yii2
在我的 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.
Yii2,在文件夹中vendor/fxp
您需要替换文件夹composer-asset-plugin
或删除它。
回答by Ivo Pereira
If none of the other solutions have worked for you, please try AssetPackagistas an alternative.
如果其他解决方案都不适合您,请尝试使用AssetPackagist作为替代方案。
Add the packagesbower-asset/bootstrapand npm-asset/jqueryto composer.json like the following:
"require": { "bower-asset/bootstrap": "^3.3", "npm-asset/jquery": "^2.2" }
Add a repositoriesblock (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
(orcomposer update
)Considering that asset-packagistinstalls 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', ], ];
将包bower-asset/bootstrap和npm-asset/jquery 添加到 composer.json 中,如下所示:
"require": { "bower-asset/bootstrap": "^3.3", "npm-asset/jquery": "^2.2" }
添加一个repositories块(如果你还没有,如果你有,只需附加到它),内容如下:
"repositories": [ { "type": "composer", "url": "https://asset-packagist.org" } ]
运行
composer install
(或composer update
)考虑到asset-packagist将资产安装在不同的目录中,将以下行添加到您的应用程序配置(通常称为 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/aboutto know more about the project.
这些说明可能会随着时间而改变。它们是从 repo 网站复制的,因此它们可以及时保存,以防万一网站发生问题。我不是 repo 的作者,但我真的很感激为此付出的努力。请查看https://asset-packagist.org/site/about以了解有关该项目的更多信息。
If you are struggling with composer, here you have some useful commands:
如果您在使用 Composer 时遇到困难,这里有一些有用的命令:
composer clear-cache
- Clear composer related caches
composer clear-cache
- 清除作曲家相关的缓存
composer install -vvv
- Add the parameter "vvv" to show installation process related output (useful to debug)
composer install -vvv
- 添加参数“vvv”以显示安装过程相关输出(用于调试)
composer global show
- Useful to check if you already have fxp/composer-asset-plugininstalled. 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!
composer global show
- 检查您是否已经安装了fxp/composer-asset-plugin很有用。在我的情况下,它已经是,但是它没有被检测为依赖项,我之前描述的解决方案对我来说完美无缺 - 希望它也对你有用!
回答by Gabb3
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
composer require fxp/composer-asset-plugin