I ran into a problem using composer for installing/uninstalling some dependencies in laravel, which come back after deleting them from composer.json and deleting their vendor folder.
I initially used dflydev's markdown package, but now I want to change it to michelf's php-markdown, but I can't uninstall the old one since it comes back loaded from cache. I checked at AppData\Roaming\Composer and it is empty.
Any clue as to why this is happening?
- Installing dflydev/markdown (dev-master dee1f7a)
Loading from cache
You can use the following command to clear the cache irrespective of the OS you are on:
php composer.phar clear-cache
or if composer is installed globally
composer clear-cache
I think, you can run your composer commands with --no-cache option flag like
composer install --no-cache
Or
composer require <package-name> --no-cache
Or
composer update [<package-name>] --no-cache
If you want to clear all packages cache, please try following:
$ composer clearcache
Or to just clear one or a few packages:
$ composer clearcache packagename1 packagename2 ...
You can also use clear-cache which is an alias for clearcache.
Source : https://blog.liplex.de/clear-composer-cache/
composer caches packages under vendor/packagename convention. So you shouldn't run into any issue, just because the packagename is used in another vendor's package.
the cache locations are:
Windows: %LOCALAPPDATA%\Composer\files\vendor\packagename
Linux: ~/.composer/cache/files/vendor/packagename
Mac OS: ~/.composer/cache/files/packagename
Don't edit your composer.json file manually to remove a package - it will remain in composer.lock.
Use composer remove to delete the old package then composer require to install the replacement.
In some cases (for example OpenSuse 42.1) all user cache are puts in:
~/.cache/
For the composer, the same as other applications, the cache path is:
~/.cache/composer/
So, just remove this folder as follow:
rm -fR ~/.cache/composer
run the following command
rm -rf ~/.composer/cache*
if Permission denied add sudo
On Window, I see the composer cache file located in
C:\Users\{your_user}\AppData\Local\Composer\files
It stores ZIP files. The below image has 2 Zip files because I have downloaded 2 versions of monolog (1.0.1 and 1.0.2)
To remove the cache, simply delete the Zip file or folder.
So the only thing that worked for me on my Macbook was removing the package from my composer.json, deleting my composer.lock, running composer update, then adding the package back to composer.json, deleting my composer.lock(again), and running composer update (again). I had a local package in my instance of Laravel Nova that I changed to all lowercase from CamelCase and no matter what I did, it kept adding the package with the old CamelCase name. Didn't matter if I cleared caches or anything.
Related
PHP laravel I have a problem in composer when installing or remove packages or writing any command for the composer
first of all your composer command should be composer remove laravel/telescope instead of vendor/telescope.
you should rename this file from app/Models/Service_old.php to app/Models/Service.php, if there is another file in the same directory with the same Service.php name, then move the old one (or change its extension) somewhere else so it will not be auto detected by composer.
at last, while the package discovery issue is not provided in the screenshot, you may run the following commands and see how things went after:
composer clear-cache
composer dump-autoload
php artisan optimize:clear
Make sure your storage/ & bootstrap/cache directory writable.
Make sure your .env file doesn't contain any spaces.
Ex: key=value instead of key=va lue
remove the bootstrap/cache/config.php file. then
composer dump-autoload
Try to remove /bootstrap/compiled.php ( if you have it )
most likely the problem is with caching as all what we do here is remove the cached files
I have a project with the composer.lock file.
I installed packages with the command:
composer install
Now I would like to rollback that composer install command to the state as it was before running it.
How to remove all packages without affecting composer.lock file?
Is there any single composer command to do that?
I tried:
composer remove *
but I got:
[UnexpectedValueException]
"LICENSE" is not a valid alias.
I tried:
composer remove */*
But then I get bunch of print like:
bin/console is not required in your composer.json and has not been removed
Package "bin/console" listed for update is not locked.
Why composer remove * did not work at all? AFAIK the package name as VendorName/PackageName is a common convention for Packagist but not a must (if you use private repos) so how one would be able to remove all packages named IdontHaveAnySlash etc. at once?
I may use someting similar to:
for package in $(composer show | awk '{print $1}'); do composer remove --no-interaction --dev --no-install "$package"; done
But that is not a simple and single composer command.
Also composer often complains about a package being a part (dependency) of another one so composer does not uninstall it.
Removal failed, doctrine/annotations is still present, it may be required by another package. See composer why doctrine/annotations.
As my intention is to rollback to the state that did not have any package installed but only files: composer.lock and potentially composer.json I really don't care about any dependencies, packages versions, downloading repositories' urls etc.
I just want to have a project without any installed dependencies as it was before.
Is there any single composer command to do that?
My:
composer --version
is:
version 2.2.7 2022-02-25 11:12:27
Following yivi answer I created a simple test to verify:
mkdir -p /tmp/composer-install
cd /tmp/composer-install
curl -o composer.json https://raw.githubusercontent.com/composer/composer/18246212db7103d0a2688febcc336f77183275ee/composer.json
curl -o composer.lock https://raw.githubusercontent.com/composer/composer/d955458f271edb4fcc055a394f90a60a8328a2a8/composer.lock
sha1sum composer.json > composer.json.sha1
sha1sum composer.lock > composer.lock.sha1
composer install
sha1sum -c composer.json.sha1
sha1sum -c composer.lock.sha1
that outputs:
composer.json: OK
composer.lock: OK
So both composer.json and composer.lock are not affected by composer install so the only one thing to achieve the rollback (uninstall) of the composer install is to remove the vendor directory
rm -rf vendor
However as yivi mentioned:
If some other plugin (e.g Symfony Flex) makes changes to your existing files during the process, you'd better have the project on top of a version control system, in which case reverting is managed by VCS, not of composer.
I did not test against that case.
rm -rf vendor
In any case, install should not make any changes to a lockfile, so there shouldn't be anything to "revert" from an install but deleting the installed files.
If the lockfile does not originally exist, then it will be created.
If some other plugin (e.g Symfony Flex) makes changes to your existing files during the process, you'd better have the project on top of a version control system, in which case reverting is managed by VCS, not of composer.
As my intention is to rollback to the state that did not have any package installed but only files: composer.lock and potentially composer.json
For you to be able to run composer install at all, you need at the very least composer.json to exist. install reads from the lockfile (composer.lock), but requires the JSON configuration file to exist as well. If the lockfile does not exist, update will be run instead and the lockfile will be created.
I tried composer remove
remove is the opposite from require. It removes packages from composer.json, as require adds them. Not the opposite of install. There is no opposite of install, as it does not make much conceptual sense. If one needs to delete the installed project... one can always do so.
I got a website which I need to maintain and after looking at the files and code, I thought there are some missing files in project/vendor folder.
After talking to the current maintainer, he told me I need to use composer in order to see those files. I have installed composer but I don't know how to "fill" the folder with the files.
From reading online I understood I need to extract and install dependencies using the composer.json file but even after searching the web for more then an hour I didn't find how to do it.
Go to the root of you project and run
composer install
after that composer will download all package that are in the composer.json file in the require and require-dev section
First, install the composer, take a look here composer, after this try to run composer install, in some cases I do update with composer update too.
Remember to run the command composer install on the same path where composer.json
Apparently I had to install php7.0-curl using the sudo apt-get install php7.0-curl.
After that I just used composer install again and it's good now
I executed these 2 commands:
composer require realrashid/sweet-alert
composer require infinety/alerts *#dev
They are packages to use SweetAlert on Laravel but they are not working and I found a better one, I want to remove them, when I do composer remove vendor/realrashid or composer remove vendor/infinety it say that the package is not installed and is not required in my composer.json, so It has not been removed but the package is still here..
No need to use vendor. Just composer remove realrashid/sweet-alert.
Another way is to go to your composer.json file and then remove that certain package then recall the 'composer update' method. Since composer remove will completely remove the library to your composer cache because you might using that library to other projects so when you try to composer install again that library, composer will download that package again instead of checking the composer cache memory.
you have to run this command in your terminal: composer remove vendor/package_name
I'm using the ZF2 skeleton app and it has a .gitignore that prevents external libraries from being commited to git. While debugging I like to go and change stuff here and there in the libraries' source to learn how things work. If these were version controlled it would be very easy to revert them back to their original state.
How can I force Composer to reinstall a particular framework so that I can get a fresh -unmodified- copy again?
PS: Please don't suggest removing the .gitignore file since it's there for a reason; it prevents my third party libraries from getting into my app's repository. I can always install them during an automated deployment.
The same applies to Laravel framework: it also gitignores the vendor folder.
First execute composer clearcache
Then clear your vendors folder
rm -rf vendor/*
or better yet just remove the specific module which makes problems to avoid having to download all over again.
You can use the --prefer-source flag for composer to checkout external packages with the VCS information (if any available). You can simply revert to the original state. Also if you issue the composer update command composer will detect any changes you made locally and ask if you want to discard them.
Your .gitignore file is related to your root project (ZF2 skeleton) and it prevents the vendor dir (where your third party libs are) from committing to your own VCS. The ignore file is unrelated to the git repo's of your vendors.
I didn't want to delete all the packages in vendor/ directory, so here is how I did it:
rm -rf vendor/package-i-messed-up
composer install again
What I did:
Deleted that particular library's folder
composer update --prefer-source vendor/library-name
It fetches the library again along with it's git repo
The relevant feature request is https://github.com/composer/composer/issues/3112
In 2021-05 the "reinstall" command patch got merged: https://github.com/composer/composer/pull/9915 - it is available in composer version 2.1.0 and all later ones.
The reinstall command is merged and availabe since 2.1.0:
composer reinstall <package-name> # Removes and installs the package.
Short answer
you can execute it in one cli command with &&:
composer remove vendor/package && composer require vendor/package:version
Detailed answer
Remove existing package by command:
composer remove vendor/package
this will remove folder of package from /vendor, row from composer.json and whole record of package from composer.lock right way with removing not used dependencies and not removing dependencies which used by another packages
Then install preferred one with command:
composer require vendor/package:version
this will install package with desired version right way with adding row to composer.json, adding record to composer.lock and all needed dependent packages
if there would be package which is used in more that one package, Composer
will try to install version which fits all using packages. If it will not resolve this it will crash with corresponding error message
Links
How to install a specific version of package using Composer?
How to remove a package from Laravel using composer?
Install, Uninstall and Update Modules Themes etc with Composer: https://modulesunraveled.com/drupal-8-composer-and-configuration-management/installing-and-uninstalling-modules-composer
Reinstall the dependencies. Remove the vendor folder (manually) or via rm command (if you are in the project folder, sure) on Linux before:
rm -rf vendor/
composer update -v
https://www.dev-metal.com/composer-problems-try-full-reset/
As user #aaracrr pointed out in a comment on another answer probably the best answer is to re-require the package with the same version constraint.
ie.
composer require vendor/package
or specifying a version constraint
composer require vendor/package:^1.0.0
For some reason no one suggested the obvious and the most straight forward way to force re-install:
> composer remove vendor-name/package-name && composer vendor-name/package-name
Be aware that this exact command will install latest version of the package. If you was using old version of the package and package does not have backward compatibility this will brake version compatibility. You might consider backing up your composer.json first.
Since Composer 2.1 you can do
composer reinstall vendor/package
see https://getcomposer.org/doc/03-cli.md#reinstall
In 2022
You can use composer status to list the libraries you changed.
Then composer resinstall vendor/package to overwrite the changes.
This does not change the version of the installed library like the solutions with composer require or composer install.