How to remove a package from Laravel using composer?

前端 未结 16 1882
[愿得一人]
[愿得一人] 2020-11-28 17:10

What is the correct way to remove a package from Laravel using composer? So far I\'ve tried:

  1. Remove declaration from composer.json (in "requir
相关标签:
16条回答
  • 2020-11-28 17:45

    There are quite a few steps here:

    1. Go to composer.json and look for the package and how it is written over there.
    • for example

    { "require": { "twig/twig": "^3.0" } }

    I wish to remove twig 3.0

    1. Now open cmd and run composer remove vendor/your_package_name as composer remove twig/twig this will remove the package.

    2. As a final step run composer update this will surely give you a massage of nothing to install or update but this is important in case your packages have inter-dependencies.

    0 讨论(0)
  • 2020-11-28 17:49

    Composer 1.x and 2.x

    Running the following command will remove the package from vendor (or wherever you install packages), composer.json and composer.lock. Change vendor/package appropriately.

    composer remove vendor/package
    

    Obviously you'll need to remove references to that package within your app.

    I'm currently running the following version of composer:

    Composer version 1.0-dev (7b13507dd4d3b93578af7d83fbf8be0ca686f4b5) 2014-12-11 21:52:29
    

    Documentation

    https://getcomposer.org/doc/03-cli.md#remove

    Updates

    • 26/10/2020 - Updated answer to assert command works for v1.x and v2.x of Composer
    0 讨论(0)
  • 2020-11-28 17:51

    If you are still getting the error after you have done with all above steps, go to your projects bootstrap->cache->config.php remove the provider & aliases entries from the cached array manually.

    0 讨论(0)
  • 2020-11-28 17:54

    Normally composer remove used like this is enough:

    $ composer remove vendor/package
    

    but if composer package is removed and config cache is not cleaned you cannot clean it, when you try like so

    php artisan config:clear
    

    you can get an error In ProviderRepository.php line 208:

    Class 'Laracasts\Flash\FlashServiceProvider' not found

    this is a dead end, unless you go deleting files

    $rm bootstrap/cache/config.php
    

    And this is Laravel 5.6 I'm talking about, not some kind of very old stuff.

    It happens usually on automated deployment, when you copy files of a new release on top of old cache. Even if you cleared cache before copying. You end up with old cache and a new composer.json.

    0 讨论(0)
  • 2020-11-28 17:54

    You can do any one of the below two methods:

    1. Running the below command (most recommended way to remove your package without updating your other packages)

      $ composer remove vendor/package

    2. Go to your composer.json file and then run command like below it will remove your package (but it will also update your other packages)

      $ composer update

    0 讨论(0)
  • 2020-11-28 17:56

    Running the following command

    composer remove Vendor/Package Name
    

    That's all. No need composer update. Vendor/Package Name is just directory as installed before

    0 讨论(0)
提交回复
热议问题