1
votes

enter image description hereI am using yii2 framework since last few weeks. But now I am getting some issues with composer itself.

Just for info, I am using ubuntu 14.04

When I require some new package / extensions, I do the composer add by using composer require command. But I noticed that sometimes it's removing few of the existing packages from my vendor and project.

I tried with following commands.

composer require dmstr/yii2-adminlte-asset "*"

composer require 2amigos/yii2-file-upload-widget:~1.0

And also tried with some googling.

http://www.yiiframework.com/wiki/672/install-specific-yii2-vendor-extension-dependency-without-updating-other-packages/

But it's not working.

Is there a way to add a new package / extension into your existing yii 2 project without removing existing packages or without any composer update command?

Composer.json

{
    "name": "sganz/yii2-advanced-api-template",
    "description": "Improved Yii 2 Advanced Application Template By Sandy Ganz, Original by Nenad Zivkovic",
    "keywords": ["yii2", "framework", "advanced", "improved", "application template", "nenad", "sganz"],
    "type": "project",
    "license": "BSD-3-Clause",
    "support": {
        "tutorial": "http://www.freetuts.org/tutorial/view?id=6",
        "source": "https://github.com/sganz/yii2-advanced-api-template.git"
    },
    "minimum-stability": "dev",
    "prefer-stable":true,
    "require": {
        "php": ">=5.4.0",
        "yiisoft/yii2": "*",
        "yiisoft/yii2-bootstrap": "*",
        "yiisoft/yii2-swiftmailer": "*",
        "nenad/yii2-password-strength": "*",
        "mihaildev/yii2-ckeditor": "*",
        "dmstr/yii2-adminlte-asset": "*"
    },
    "require-dev": {
        "yiisoft/yii2-codeception": "*",
        "yiisoft/yii2-debug": "*",
        "yiisoft/yii2-gii": "*",
        "yiisoft/yii2-faker": "*",
        "codeception/specify": "*",
        "codeception/verify": "*"
    },
    "config": {
        "vendor-dir": "protected/vendor",
        "process-timeout": 1800
    },
    "extra": {
        "asset-installer-paths": {
            "npm-asset-library": "protected/vendor/npm",
            "bower-asset-library": "protected/vendor/bower"
        }
    }
}

Any help on this would be greatly appreciated.

4
Check if the packages which are removed are required in your composer.json (before you run composer require). It also can be that the removed packages are sub requirements of another package which was updated (composer require automatically runs a composer update) and are no longer needed by this package.Pᴇʜ
@Peh I've an existing big project developed long time ago, now when I am trying to add new packages, it's removing some of the existing packages.Mohit Tanwani
OK, can you edit your question and show your composer.json and a list of the packages which are removed?Pᴇʜ
@Peh You can see the screen shot which shows which packages are removed.Mohit Tanwani
And your composer.json?Pᴇʜ

4 Answers

3
votes

Try

composer --no-update require dmstr/yii2-adminlte-asset:*
0
votes
  1. Your problem is, that the packages which are removed are NOT in the require nor in require-dev section of your composer.json. So I assume that the removed packages formerly were (sub-)required by any of the other packages in your composer.json and with the newer version of these packages this requirement was dropped. This should be a normal behavior and should be no problem for your project!

  2. As @Bizley already showed you can add a requirement without updating the old ones:

    composer --no-update require dmstr/yii2-adminlte-asset:*
    
0
votes

I had this problem few days ago to install a package but when I installed the package all the project updated and my project became broken.So I replace my last vendor again,So I found a safe way for better and safer upgrading packages:

  1. archiving your vendor to a zip or rar file and copy composer.json too.
  2. add package to composer or install with composer require.
  3. dont clear command line screen and copy its screen into a txt file to find versions
  4. find your vital and main packages like yiisoft/yii2 and .... and copy their versions.
    for doing this open txt file and search in upgrade lines and find something like below:
    - Upgrading yiisoft/yii2 (2.0.39.3 => 2.0.41.1): Extracting archive means that your current version is 2.0.39.3,so copy this version on composer.json like below:(without ~ and ^)
    "yiisoft/yii2": "2.0.39",
  5. remove project vendor folder and extract backup vendor and finally run composer install or composer update.

note: dont remove vendor and composer.json backup till your project will works correctly then you can remove them.
*this is a manually way for upgrading vendors for don't upgrade in vital framework updates temporary like for my project update that yii released Yii2.0.41.
a very important note is from yii upgrade notes from here that:

Note: This document assumes you have composer installed globally so that you can run the composer command. If you have a composer.phar file inside of your project you need to replace composer with php composer.phar in the following.

Tip: Upgrading dependencies of a complex software project always comes at the risk of breaking something, so make sure you have a backup (you should be doing this anyway ;) ).

so running composer update command directly could break part of your application like me that my admin pannel was broken.

good luck ;)

-1
votes

To avoid uninstallation of other extensions just do following steps.

1) "dmstr/yii2-adminlte-asset"  : "2.*" 
2) "2amigos/yii2-file-upload-widget": "~1.0"

to the require section of your composer.json file.

2) php composer.phar update

run this command in Cmd.