Laravel composer install giving error "Your lock file does not contain a compatible set of packages please run composer update"

Viewed 83355

I have been writing laravel code for quite sometime. Currently, I tried cloning a project from github and editing locally. I installed composer in my project directory but a vendor folder was not included, I tried to run composer install but I gives me this error

Your lock file does not contain a compatible set of packages. Please run composer update

How do I resolve this?

Note: I have tried running composer update on previous clones and that didn't work.

8 Answers

Run this command:

composer install --ignore-platform-reqs

or

composer update --ignore-platform-reqs

Disclaimer, this solution will not fix the issue for PHP 8 projects.

In most cases this happens because of PHP 8 (In my case it was GitHub CI actions automatically started using PHP 8 even though my project is php 7.4)

If you have multiple PHP installations (E.g. 7.4 and 8 on the same server), this is how you can fix it.

Specify your php version in your composer.json file

"config": {
        "platform": {
            "php": "7.3"
        }
    },

If you have the lock file already committed, run composer update after you adding above line in to the composer.json and then commit the new lock file. (Please be aware composer update will upgrade your packages to latest versions)

I solved this problem with this command:

composer self-update --1

It probably works because at time that the project was developed, composer was on another version and when change the Major version from 1 to 2 the compatibility was broke. With this command you downgrade composer and probably going to solve this

You should try running composer update --lock that will update all packages and recreate the compose.lock file.

Either you can delete the composer.lock file and run composer install that will also recreate the .lock file.

This resolved my issue.

I had this error with Github Actions trying to deploy a Laravel app, this is probably different than the OP's case but none of the suggestions worked for me. Adding my answer here just in case there is someone else out there with a similar problem to mine.

I had to disable -q in Github Actions and see that it was complaining about extensions not being installed.

Make sure your require section of composer's php extensions matches the extensions: in your github action file for shivammathur/setup-php@v2 and it will deploy again

I faced this problem with my cakephp project in garuda linux (arch based)

Fix :

  1. Install php-intl using sudo pacman -S php-intl
  2. Enable php intl by editing php config ( in my case /etc/php/php.ini ) . add extension=intl or uncomment the existing one
  3. restart apache or whatever you are using

I had the same error deploying another project with composer, but the problem was a missing php extension.

I understand you solve your problem but for anyone seeing the same error message, here is a general guidance :

The error message Your lock file does not contain a compatible set of packages. Please run composer update is shown each time there is a conflict during the dependency solving step of composer install. (see the relevant part in composer source code)

It doesn't inform on the real problem though, and it could be hard to guess.

To get the exact explanation you can add --verbose option to composer install command (the option is available to any composer command (see the doc)) : composer install --verbose

It will give you the full message explaining what exactly is preventing composer install from completing (package version conflict, missing php extension, etc.), then you'll be able to fix the problem.

Hope this could help.

In my case this problem is occuring in Ubuntu 20.04 Desktop. This is due to some missing packages.

I ran the following commands to install some packages then rerun Composer install and its working properly. The commands are:

sudo apt-get install php-mbstring

sudo apt-get install php-xml

Then rerun composer install

Related