Change record status: 
Project: 
Introduced in branch: 
9.4.x
Introduced in version: 
9.4.0
Description: 

In Drupal 9.3.9 and up, an incompatibility with Composer 2 has been fixed.

This incompatibility affects a minority of sites in certain situations, but can result in fatal errors like this one whenever you try to update certain Composer packages:

> Drupal\Core\Composer\Composer::vendorTestCodeCleanup

Fatal error: Uncaught Error: Call to undefined method Composer\DependencyResolver\Operation\UpdateOperation::getJobType()

Workarounds

There are three possible workarounds to this problem, which you can use to get to a version of Drupal that fixes the error. They are detailed here in order of most preferable to least preferable.

Workaround #1

Remove the post-package-install and post-package-update scripts from your project's composer.json. This will fix the problem permanently without requiring you to update Drupal. You can run the following commands to make this change:

composer config --unset scripts.post-package-install
composer config --unset scripts.post-package-update
composer require drupal/core-vendor-hardening:^9
Workaround #2

Temporarily roll back to Composer 1 to update to a fixed version of Drupal core. This will only work if you have permission to overwrite the Composer executable. You can run the following commands:

composer self-update --1
composer require drupal/core:~9.3.9 drupal/core-vendor-hardening:^9 --update-with-all-dependencies
composer self-update --rollback
Workaround #3

You can temporarily disable Composer scripts from running while you update to a fixed version of Drupal core. This is the least preferable workaround because it may cause unintended side effects if your project is relying on Composer scripts to do important tasks. You can run the following commands:

composer require drupal/core:~9.3.9 drupal/core-vendor-hardening:^9 --update-with-all-dependencies --no-scripts

What causes this?

Prior to Drupal 8.8, sites created from the drupal/drupal Composer project, which also included tarballs, defined a post-package-install and post-package-update script in their composer.json. This script calls a function which only exists in Composer 1. As of Drupal 8.8, the script was replaced by the drupal/core-vendor-hardening plugin, and is no longer defined in composer.json. However, the script was not retroactively removed from the existing composer.json, so Composer 2 will try to run it when updating or installing a package, and fail with a fatal error when calling the non-existent function.

Impacts: 
Site builders, administrators, editors