This is a common issue developers experience when using Composer in Drupal 8.
For my local development I use MAMP and by default the memory limit is set to 128M. Depending on your development environment, your number can vary.
I will be using MAMP in this example, but you can also use these steps to help with your Drupal development using Composer.
When you see the following error message, it is very likely that you have a memory limit issue and you need to increase it in the PHP config file.
PHP Fatal error: Allowed memory size of XXXXXX bytes exhausted <...>
To find out what the current memory limit is, run the following command:
php -r "echo ini_get('memory_limit').PHP_EOL;"
After running the command, this is my current memory limit.
128M
Since the memory limit is 128M, it is a good idea to increase it.
To increase the memory limit, we need to locate the PHP config file. We can simply run the following command:
php --ini
Here is an example of what you should expect after running the command.
Configuration File (php.ini) Path: /Applications/MAMP/bin/php/php7.0.8/conf
Loaded Configuration File: /Applications/MAMP/bin/php/php7.0.8/conf/php.ini
Scan for additional .ini files in: (none)
Additional .ini files parsed: (none)
The path to the PHP config file is next to `Loaded Configuration File`.
In your favorite text editor open the php.ini file. Search for memory_limit and increase the value. For instance:
memory_limit = 512M;
After saving the file, we can see our memory has increased.
php -r "echo ini_get('memory_limit').PHP_EOL;"
512M