Fixing the Composer Undefined index: extra ErrorException

Yesterday was one of those days where I woke up, scrolled through Twitter, and tried really hard not to process much of what I was seeing. I sort of noticed a tweet about composer but like I said... I didn't process it. Boy I wish I had.

The Issue

Running a simple composer command like `composer update` results in:

[ErrorException]        
Undefined index: extra 

That's not ideal (obviously) because ther's a lot of good stuff in the extra key. A quick Google found a number of issues, and ultimately I landed on https://github.com/zaporylie/composer-drupal-optimizations/issues/18 (which is exactly what Tracy linked to in the Tweet I saw, but didn't dig into.) As it turns out, all you have to do is update zaporylie/composer-drupal-optimizations to version 1.1.2 and the problem goes away! The NEXT issue is that

composer show zaporylie/composer-drupal-optimizations

[InvalidArgumentException]                                 
Package zaporylie/composer-drupal-optimizations not found 

This threw me for a couple of minutes. This was really obviously the error I was facing, but I wasn’t using the package that was known to cause the problem. WTF? Then I remembered that I'm actually using this package globally. So I re-ran the above command with the global flag.

composer global show zaporylie/composer-drupal-optimizations
Changed current directory to /Users/mike.madison/.composer
name     : zaporylie/composer-drupal-optimizations
descrip. : Composer plugin to improve composer performance for Drupal projects
keywords : 
versions : * 1.1.1
type     : composer-plugin
license  : GNU General Public License v2.0 or later (GPL-2.0-or-later) (OSI approved) https://spdx.org/licenses/GPL-2.0-or-later.html#licenseText
homepage : 
source   : [git] https://github.com/zaporylie/composer-drupal-optimizations.git fb231d92adc862a2c9276bccbc90f684816dc75d
dist     : [zip] https://api.github.com/repos/zaporylie/composer-drupal-optimizations/zipball/fb231d92adc862a2c9276bccbc90f684816dc75d fb231d92adc862a2c9276bccbc90f684816dc75d
path     : /Users/mike.madison/.composer/vendor/zaporylie/composer-drupal-optimizations
names    : zaporylie/composer-drupal-optimizations

The Solution

All you have to do to fix this is to run

composer global update zaporylie/composer-drupal-optimizations.  

The problem with this is that everyone on your team will have to do this. If you have multiple environments that use composer you'll have to do it on there, too. Easy, but annoying fix. Big thanks to zaporylie for the very prompt responses and fix!

Related Content