Project

General

Profile

Actions

Bug #96081

closed

ClassAliasLoader throws Exception with composer 2.2

Added by Tizian Schmidlin over 2 years ago. Updated over 2 years ago.

Status:
Closed
Priority:
Should have
Assignee:
-
Category:
-
Target version:
Start date:
2021-11-25
Due date:
% Done:

0%

Estimated time:
TYPO3 Version:
11
PHP Version:
Tags:
composer
Complexity:
Is Regression:
Sprint Focus:

Description

Composer 2.2 throws an exception when updating:


  [RuntimeException]                                         
  Cannot set the alias loader, as it is already registered!  

Exception trace:

Exception trace:
 () at /Users/st/scripts/projects/.../src/vendor/typo3/class-alias-loader/src/ClassAliasMap.php:72
 TYPO3\ClassAliasLoader\ClassAliasMap::setClassAliasLoader() at /Users/st/scripts/projects/.../src/vendor/typo3/alias-loader-include.php:9
 require() at phar:///Users/st/.composer/vendor/bin/composer-dev/src/Composer/Autoload/AutoloadGenerator.php:1419
 Composer\Autoload\composerRequire() at phar:///Users/st/.composer/vendor/bin/composer-dev/src/Composer/EventDispatcher/EventDispatcher.php:512
 Composer\EventDispatcher\EventDispatcher->getScriptListeners() at phar:///Users/st/.composer/vendor/bin/composer-dev/src/Composer/EventDispatcher/EventDispatcher.php:455
 Composer\EventDispatcher\EventDispatcher->getListeners() at phar:///Users/st/.composer/vendor/bin/composer-dev/src/Composer/EventDispatcher/EventDispatcher.php:172
 Composer\EventDispatcher\EventDispatcher->doDispatch() at phar:///Users/st/.composer/vendor/bin/composer-dev/src/Composer/EventDispatcher/EventDispatcher.php:118
 Composer\EventDispatcher\EventDispatcher->dispatchScript() at phar:///Users/st/.composer/vendor/bin/composer-dev/src/Composer/Installer.php:371
 Composer\Installer->run() at phar:///Users/st/.composer/vendor/bin/composer-dev/src/Composer/Command/UpdateCommand.php:249
 Composer\Command\UpdateCommand->execute() at phar:///Users/st/.composer/vendor/bin/composer-dev/vendor/symfony/console/Command/Command.php:245
 Symfony\Component\Console\Command\Command->run() at phar:///Users/st/.composer/vendor/bin/composer-dev/vendor/symfony/console/Application.php:835
 Symfony\Component\Console\Application->doRunCommand() at phar:///Users/st/.composer/vendor/bin/composer-dev/vendor/symfony/console/Application.php:185
 Symfony\Component\Console\Application->doRun() at phar:///Users/st/.composer/vendor/bin/composer-dev/src/Composer/Console/Application.php:332
 Composer\Console\Application->doRun() at phar:///Users/st/.composer/vendor/bin/composer-dev/vendor/symfony/console/Application.php:117
 Symfony\Component\Console\Application->run() at phar:///Users/st/.composer/vendor/bin/composer-dev/src/Composer/Console/Application.php:128
 Composer\Console\Application->run() at phar:///Users/st/.composer/vendor/bin/composer-dev/bin/composer:73
 require() at /Users/st/.composer/vendor/bin/composer-dev:30

When reverting to composer 2.1, the error vanishes.

I'm planning on creating an comment in the official discussion about this as well, but IMHO this is an issue with TYPO3 and not composer itself.

I was able to ensure that this issue was not due to additional packages like "helhum/typo3-console" or others.

Way to reproduce (as of 25.11.2021):
  1. Install composer snapshot (composer self-update --snapshot)
  2. Update packages (composer update)
Actions #1

Updated by Helmut Hummel over 2 years ago

Tizian Schmidlin wrote:

Composer 2.2 throws an exception when updating:

I can not reproduce that. Please post the composer.json with which you are able to reproduce this exception.

Actions #2

Updated by Tizian Schmidlin over 2 years ago

I've been able to pinpoint the reason. As it appears (and this was to be expected), this comes from a post-update-script that was needed in older versions and that was never removed:

Excerpt:

...
  "scripts": {
    "post-update-cmd": [
      "bash scripts/include-fpm.sh" 
    ],
...

include-fpm.sh

#!/usr/bin/env bash

match='<?php'
file='vendor/typo3/autoload-include.php'

if grep -r "REDIRECT_TYPO3_PATH_ROOT" $file
then
    echo "already ok" 
    exit
else
    echo "<?php" > $file.new
    cat scripts/add.txt >> $file.new
    cat $file | tail -n +2 >> $file.new
    rm $file && mv $file.new $file
fi

This lead to the autoloader registering the class alias mapper twice, which did not seem to be an issue before 2.2 but now apparently is.

Ticket can be closed.

Actions #3

Updated by Helmut Hummel over 2 years ago

Let's see if the proposed fix in Composer is accepted. https://github.com/composer/composer/pull/10312

Otherwise the class alias loader package needs to adapt

Actions #4

Updated by Helmut Hummel over 2 years ago

  • Status changed from New to Closed

Now fixed in Composer

Actions

Also available in: Atom PDF