Solving the “Two packages cannot share the same directory!” Composer error

If you use Composer to manage dependencies on your WordPress site, you probably know the name John P. Bloch. He maintains a regularly-updated fork of WordPress that’s tailored for use with Composer. It turns up a lot in WordPress boilerplate.

Recently he made some changes to his fork, moving some of the core WordPress components to a separate repository named (appropriately) wordpress-core.

This isn’t a problem if you’re setting up a new project, as when you run composer install it will install the now three repositories (johnpbloch/wordpress, johnpbloch/wordpress-core-installer, and now johnpbloch/wordpress-core) in vendor/johnpbloch.

If you’re reading this page, you tried running composer update on an existing project and received this error message:

Two packages cannot share the same directory!

The solution is pretty simple, if a little dramatic: Use Composer to remove then reinstall WordPress.

I say “dramatic” because for that brief period after you’ve finished removing WordPress and before you’ve finished reinstalling it, your site will be a whole lot of nothing, so move with a purpose.

  1. Find the line in your composer.json file that calls for WordPress. Depending on what—if any—version you’re requiring, it should look something like this:

    "johnpbloch/wordpress": "4.7.3"

    Once you find it, delete it and save your composer.json.

  2. Run composer update. Composer will remove johnpbloch/wordpress and johnpbloch/wordpress-core-installer.
  3. Add the line back to your composer.json and save, then run composer update again. Composer will install the three repositories.

And that should be it.