Troubleshooting Composer

Last updated on
10 July 2017

Troubleshooting Composer can be frustrating. Composer is doing many complex things for you, and there's a degree of understanding required to effectively troubleshoot issues that arise. 

This page is intended to provide troubleshooting techniques and to enumerate common problems. It is not intended to be exhaustive. If you're having a problem not described here, performing an internet search for your specific error message may be more helpful.

Troubleshooting techniques

Increase Composer's verbosity

E.g.,. when troubleshooting composer require drupal/module_name try adding a -vvv flag:

composer require drupal/module_name -vvv

Update Composer itself

Outdated versions of Composer can cause problems.

To update Composer itself to the latest version, just run the self-update command:

composer self-update

Common issues

Incompatibility with drush pm-updatecode

Some Drupal projects, such as Address, state something like "Address must be installed via Composer, in order to get the required libraries." While that is true, the user is not told that once one begins to use Composer to install modules and dependencies then any further use of Drush to update code via pm-updatecode will permanently hose up their entire Drupal site. And unfortunately they will not find out that their site is hosed until the next time they run drush pm-updatecode. That will lead to highly charged discussions like this.

A faulty commit by a module developer can prevent any site from being updated

If you are using a module that has been installed by composer and the maintainer of that module releases a faulty .json file, then it is possible that any site that has that module listed in its composer.lock file will get errors when composer require is run. That is true because composer require will download the latest .json file every module that is listed in composer.lock. So if you have 50 modules being maintained by composer then a mistake introduced into any of the 50 modules will prevent your site from being updated, as has happened here. That is true even though the code you are trying to download via composer require has nothing to do with the faulty module.

Insufficient memory

Related errors include :

Fatal error: Allowed memory size
Fatal error: Uncaught exception 'ErrorException' with message 'proc_open(): fork failed -

The workaround for these errors is to execute composer with more or maximum available memory the system can provide. There are a variety of methods for accomplishing this. Some examples:
php -d memory_limit=-1 [composer-location] require drupal/module_name -vvv

Concrete Examples :
php -d memory_limit=-1 /usr/local/bin/composer require "drupal/address ~8.1" -vvv
php -d memory_limit=-1 /usr/local/bin/composer.phar require "drupal/address ~8.1" -vvv

Composer hangs and eventually times out

Connection timeouts are often related to problems with IPv6, either on your computer or with your ISP. Verify this by turning IPv6 off.  This GitHub issue and these workarounds for Windows, Mac and Linux may help too.

packagist.drupal-composer has been shut down

If you get the following error you are attempting to reach a discontinued composer repository:

[Composer\Downloader\TransportException]
The “https://packagist.drupal-composer.org/packages.json" file could not be downloaded: failed to open stream: Connection refused

If you are on Drupal 8, your composer.json file should be updated with code like this:

 { 
    "repositories": { 
        "drupal": {
            "type": "composer",
            "url": "https://packages.drupal.org/8" 
        }
    }
}

More info here about this repository shutdown. Official documentation is here for setting up your project correctly.

Core update fails via composer update drupal/core

If you run composer update drupal/core and it fails with the message: 

Package "drupal/core" listed for update is not installed

Try opening composer.json and searching for a drupal/core entry in "replace"

   "replace": {
        "drupal/core": "~8.3"
    },

One solution is to move drupal/core from "replace" to "require", as below. 

     "drupal/twitter_block": "^2.1",
     "drupal/core": "~8.3"
    },
    "replace": {},

(Remember JSON format requires a comma for all but the last item in each block.)  The empty replace section can be left or removed.

Composer is too slow when checking dependencies

There are some shortcomings to how Composer sequences its fetches. An plugin called prestissimo by hirak improves performance substantially by downloading packages in parallel. Installation is simple if you have access to global composer.

$ composer global require hirak/prestissimo

To uninstall:

$ composer global remove hirak/prestissimo