Tuesday, 4 May 2021

How to solve composer's InvalidArgumentException Errror in Drupal 8?

Solving the composer require drupal/csv_serialization Error

The other day, I was following the Drupal documentation and tried to install the csv_serialization module with this command:

composer require drupal/csv_serialization

Instead of a smooth install, I got slapped with this error:

[InvalidArgumentException]  
Could not find a matching version of package drupal/csv_serialization.  
Check the package spelling, your version constraint and that the package is available in a stability which matches your minimum-stability (stable).

At first, it felt like I had messed up the spelling or version, but that wasn’t the case. The issue was actually with Composer not knowing where to look for Drupal packages.


The Fix

All you need to do is tell Composer about Drupal’s official package repository. Run this command:

composer config repositories.drupal composer https://packages.drupal.org/8

Once that’s set up, try the install again:

composer require drupal/csv_serialization

This time it should work without any issues. 🎉


💡 Tip: If you run into similar errors with other Drupal modules, chances are you just need to make sure the Drupal repository is added to your Composer config.


No comments:

Post a Comment