Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
908 views
in Technique[技术] by (71.8m points)

composer php - How to resolve a "Can only install one of:" conflict?

I have installed one package via Composer and it installed Guzzlehttp too, because of the package. After that I tried to install another package via Composer, which requires Guzzlehttp too and Composer, tried to install it again.

But I get that error :

Problem 1

  • Can only install one of: guzzlehttp/guzzle[6.2.0, 6.0.2].

  • Can only install one of: guzzlehttp/guzzle[6.0.2, 6.2.0].

  • Can only install one of: guzzlehttp/guzzle[6.0.2, 6.2.0].

I see what is the problem, but I do not know how to fix it.

Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The "Can only install one [x, y]" message appears when two different packages point to the same dependency, but different major, mutually exclusive versions where only one can be installed.


Troubleshooting

For example, one version can be "locked at" due to the information present in your composer.lock file which may conflict with what you're trying to install. In this case, when the confusion error comes with "locked at x.y.z" message, you may use the following commands to understand the existing dependencies of installed packages:

composer show -t

Note: -t shows as a nested tree view, drop it to see the flat list.

To see where the problematic package is referenced from in your project, run:

composer why org/package -t

Note: -t shows as a nested tree view, drop it to see the flat list.

To see the details of the package which you're trying to install, you may run:

composer show -a org/package # Package to inspect.

Note: To inspect the specific version, add x.y.z, e.g.: composer show -a guzzlehttp/guzzle 6.2.0


To further troubleshoot the problem, depending on your situation, you can try to:

  • Update the existing packages with dependencies via:

    composer update --with-dependencies
    
  • Upgrade or remove conflicting dependencies from your composer.json (keep it simple).

  • When the confusion message shows "locked at x.y.z", use composer why org/package to see where the package is referenced (or check the content of composer.lock manually by looking for x.y.z). If won't help, consider removing composer.lock and re-try again;
  • When asked to use composer.json from the different folder, select n.
  • Re-try your plain composer.json, simplified configuration on the empty folder.
  • Run composer diagnose to check for any common error.
  • Use -v/-vv/-vvv to increase the verbosity of your commands.
  • See also: How to explain Composer's error log?

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...