Issue:
You may encounter package installation or update conflicts with Composer in Magento. The error message might include something like "..from composer repo (https://repo.magento.com) has higher repository priority. The packages from the higher priority repository do not match your constraint and are therefore not installable. That repository is canonical so the lower priority repo's packages are not installable."
In this KB article, we'll outline two possible solutions to resolve package conflicts with Composer in Magento.
Solution 1: Adjust Package Constraints and Update Composer
1. Update your composer.json
file: Check the composer.json
file in your Magento root directory and ensure that the package constraints are defined correctly. You might need to adjust the version constraints for the problematic package to match the available versions in the Magento repository.
2. Run composer update
: After updating the composer.json
file, run the composer update command in your Magento root directory. This will update the dependencies and try to resolve the conflict.
3. Check for additional repositories: If the issue persists, make sure that there are no additional repositories with lower priority than the Magento repository in your composer.json
file. If you find any, either remove them or adjust their priorities accordingly.
4. Clear Composer cache: Sometimes, the Composer cache can cause conflicts. Run the following command to clear the Composer cache:
composer clear-cache
5. Re-run the Composer command: After clearing the cache, try running the installation or update command again.
Solution 2: Change the Canonical Status of the Magento Repository
1. Update your composer.json
file: Locate the Magento repository definition in your composer.json
file and add "canonical": false
. This tells Composer not to treat the Magento repository as the authoritative source for packages, allowing packages from other repositories with lower priority to be installed.
Example:
{ "type": "composer", "url": "https://repo.magento.com/", "canonical": false }
2. Save the composer.json
file and run composer update
to update the dependencies and resolve any conflicts.
3. Be cautious when using "canonical": false
, as it can lead to unexpected results if you have multiple repositories with overlapping packages. Verify that the packages you're installing from other repositories are compatible with your Magento installation and that you're not introducing any security vulnerabilities or breaking changes.
References:
- Composer documentation
- https://magefan.com/blog/package-exists-in-composer-repo-1-and-composer-repo-2-which-has-a-higher-repository-priority
If you are a Create Hosting customer utilising our MageVPS Plan, feel free to submit a support ticket and we can investigate and take care of this issue for you.