安装 yii2 出现 Class Fxp\Composer\AssetPlugin\Repository\NpmRepository does not exist


作者: 我不是鱼 (2016-05-22 21:21) 分类: PHP   标签: yii2安装错误 NpmRepository not exist

yii2 官网给出的安装命令是:

composer global require "fxp/composer-asset-plugin:~1.0.0"
composer create-project --prefer-dist yiisoft/yii2-app-basic basic

原本以为会很顺利,没想到按这个做却没能成功,出现这个错误:

Thomass-MacBook-Pro:projects Thomas$ composer global require "fxp/composer-asset-plugin:~1.0.0"
Changed current directory to /Users/Thomas/.composer
./composer.json has been created
Loading composer repositories with package information
Updating dependencies (including require-dev)
  - Installing fxp/composer-asset-plugin (v1.0.3)
    Downloading: 100%        
Deprecation Notice: The Composer\Package\LinkConstraint\MultiConstraint class is deprecated, use Composer\Semver\Constraint\MultiConstraint instead. in phar:///usr/local/bin/composer/src/Composer/Package/LinkConstraint/MultiConstraint.php:17
Deprecation Notice: The Composer\Package\LinkConstraint\LinkConstraintInterface interface is deprecated, use Composer\Semver\Constraint\ConstraintInterface instead. in phar:///usr/local/bin/composer/src/Composer/Package/LinkConstraint/LinkConstraintInterface.php:17
Plugin installation failed, rolling back
  - Removing fxp/composer-asset-plugin (v1.0.3)
Installation failed, deleting ./composer.json.
                                                                      
  [ReflectionException]                                                   
  Class Fxp\Composer\AssetPlugin\Repository\NpmRepository does not exist  
                                                                                                                                                                            
  [ErrorException]                                                                                 
  Declaration of Fxp\Composer\AssetPlugin\Repository\AbstractAssetsRepository::whatProvides() sho  
  uld be compatible with Composer\Repository\ComposerRepository::whatProvides(Composer\Dependency  
  Resolver\Pool $pool, $name, $bypassFilters = false)

网上说用这个代替可以解决:

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

特意试了一下:

Thomass-MacBook-Pro:projects Thomas$ composer global update fxp/composer-asset-plugin --no-plugins
Changed current directory to /Users/Thomas/.composer
Composer could not find a composer.json file in /Users/Thomas/.composer
To initialize a project, please create a composer.json file as described in the https://getcomposer.org/ "Getting Started" section

其实不然,虽然这步没出现错误,但下一步安装 yii2 有出现这个问题:

Thomass-MacBook-Pro:projects Thomas$ composer create-project --prefer-dist yiisoft/yii2-app-basic basic
Installing yiisoft/yii2-app-basic (2.0.8)
  - Installing yiisoft/yii2-app-basic (2.0.8)
    Downloading: 100%        
Created project in basic
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.
  Problem 1
    - yiisoft/yii2 2.0.8 requires bower-asset/jquery 2.2.*@stable | 2.1.*@stable | 1.11.*@stable -> no matching package found.
    - yiisoft/yii2 2.0.7 requires bower-asset/jquery 2.2.*@stable | 2.1.*@stable | 1.11.*@stable -> no matching package found.
    - yiisoft/yii2 2.0.6 requires bower-asset/jquery 2.1.*@stable | 1.11.*@stable -> no matching package found.
    - yiisoft/yii2 2.0.5 requires bower-asset/jquery 2.1.*@stable | 1.11.*@stable -> no matching package found.
    - Installation request for yiisoft/yii2 >=2.0.5 -> satisfiable by yiisoft/yii2[2.0.5, 2.0.6, 2.0.7, 2.0.8].

感觉应该是 composer-asset-plugin 这个版本的某些类库的文件夹或命名空间发生了变化导致类找不到,这里暂时不纠结这个问题,尝试安装最新版的  composer-asset-plugin 版本看看能不能解决这个问题。现在最新版本是 1.1.4  https://packagist.org/packages/fxp/composer-asset-plugin

Thomass-MacBook-Pro:projects Thomas$ composer global require "fxp/composer-asset-plugin:~1.1.4"
Changed current directory to /Users/Thomas/.composer
./composer.json has been created
Loading composer repositories with package information
Updating dependencies (including require-dev)
  - Installing fxp/composer-asset-plugin (v1.1.4)
    Downloading: 100%
Writing lock file
Generating autoload files
Thomass-MacBook-Pro:projects Thomas$

再安装 yii2 :

Thomass-MacBook-Pro:projects Thomas$ composer create-project --prefer-dist yiisoft/yii2-app-basic lnmp.cn
Installing yiisoft/yii2-app-basic (2.0.8)
  - Installing yiisoft/yii2-app-basic (2.0.8)
    Downloading: 100%        

Created project in lnmp.cn
Loading composer repositories with package information
Updating dependencies (including require-dev)
  - Installing yiisoft/yii2-composer (2.0.4)               
    Downloading: 100%  

终于成功安装 yii2 了。

前一篇: 安装 PHP 出现 cannot find -lltdl 错误
后一篇: Laravel No supported encrypter found. The cipher and / or key length are invalid.


添加评论

昵称:


验证码