Closed
Description
What happened?
Description
Starting today in every Craft 3.4.5 project where we have removed the composer.lock and vendor folder and then after reinstalling the composer packages and trying to install or update any Craft plugin, it get's interrupted with following error:
Error: count(): Argument #1 ($value) must be of type Countable|array, Closure given
Composer output: Loading composer repositories with package information
Updating dependencies
When looking at the web.log file we found following stack:
2022-12-22 19:06:11 [web.ERROR] [TypeError] TypeError: count(): Argument #1 ($value) must be of type Countable|array, Closure given in /Users/****/vendor/composer/composer/src/Composer/Autoload/AutoloadGenerator.php:1202
Stack trace:
#0 /Users/****/vendor/composer/composer/src/Composer/Autoload/AutoloadGenerator.php(1202): count(Object(Closure))
#1 /Users/****/vendor/composer/composer/src/Composer/Autoload/AutoloadGenerator.php(412): Composer\Autoload\AutoloadGenerator->getStaticFile('ec23c9847411143...', '/Users/...', '/Users/...', '/Users/...', 50600)
#2 /Users/****//vendor/composer/composer/src/Composer/Installer.php(341): Composer\Autoload\AutoloadGenerator->dump(Object(Composer\Config), Object(Composer\Repository\InstalledFilesystemRepository), Object(Composer\Package\RootPackage), Object(Composer\Installer\InstallationManager), '/Users/****/...', false)
#3 /Users/****/vendor/craftcms/cms/src/services/Composer.php(583): Composer\Installer->run()
#4 /Users/****/vendor/craftcms/cms/src/services/Composer.php(190): craft\services\Composer->run(Object(Composer\Installer))
#5 /Users/****//vendor/craftcms/cms/src/controllers/BaseUpdaterController.php(174): craft\services\Composer->install(Array, Object(Composer\IO\BufferIO))
#6 [internal function]: craft\controllers\BaseUpdaterController->actionComposerInstall()
#7 /Users/****/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#8 /Users/****/vendor/yiisoft/yii2/base/Controller.php(178): yii\base\InlineAction->runWithParams(Array)
#9 /Users/****/vendor/yiisoft/yii2/base/Module.php(552): yii\base\Controller->runAction('composer-instal...', Array)
#10 /Users/****/vendor/craftcms/cms/src/web/Application.php(301): yii\base\Module->runAction('pluginstore/ins...', Array)
#11 /Users/****//vendor/craftcms/cms/src/web/Application.php(625): craft\web\Application->runAction('pluginstore/ins...', Array)
#12 /Users/****/vendor/craftcms/cms/src/web/Application.php(280): craft\web\Application->_processActionRequest(Object(craft\web\Request))
#13 /Users/****//vendor/yiisoft/yii2/base/Application.php(384): craft\web\Application->handleRequest(Object(craft\web\Request))
#14 /Users/****//web/index.php(15): yii\base\Application->run()
#15 /Users/****//.composer/vendor/laravel/valet/server.php(235): require('/Users/****/...')
#16 {main} {"memory":11950200,"exception":"[object] (TypeError(code: 0): count(): Argument #1 ($value) must be of type Countable|array, Closure given at /Users/****//vendor/composer/composer/src/Composer/Autoload/AutoloadGenerator.php:1202)"}
2022-12-22 19:06:11 [web.INFO] [application] Request context:
$_GET = [
'p' => 'admin/actions/pluginstore/install/composer-install'
'v' => '1671735964331'
]
The errors and the location of it led me to this issue on the composer repo:
composer/composer#11234
I'm afraid I don't really understand that much of what is described here, but if I understand it correctly, either we have to downgrade our own composer version or have the Craft CMS one upgraded?
Craft CMS version
3.4.5
PHP version
8.1 & 8.2
Operating system and version
MacOS13
Database type and version
No response
Image driver and version
No response
Installed plugins and versions
Composer version 2.5.0
Activity
ishetnogferre commentedon Dec 23, 2022
Locally or in ddev changing the composer version to either 2.4.4 or 2.5.1 has fixed it for now
brandonkelly commentedon Dec 24, 2022
Craft explicitly requires Composer
2.2.15
for its internal Composer operations:cms/composer.json
Line 38 in bb51407
We do that because there were breaking changes introduced in 2.3. Why and how are you on a different version?
ishetnogferre commentedon Dec 27, 2022
@brandonkelly the composer in the vendor folder is indeed
2.2.15
.My local composer version and the one in ddev (for the command line) was
2.5.0
and somehow this setup seems to give the above count error.brianjhanson commentedon Dec 27, 2022
I'm going to close this one out because upgrading/downgrading composer is the best fix at the moment. It looks like the original issue you linked to confirms there are some issues when running in a setup like ours. Hopefully, we can work through the breaking changes and get the internal version of composer updated, which should solve this.
brandonkelly commentedon Dec 28, 2022
Ah I get it, it’s an issue that comes up when using Craft’s built-in copy of Composer with autoload files that were generated by Composer 2.5.
brandonkelly commentedon Dec 31, 2022
Looks like the issue has been fixed for the next Composer 2.2 release, so we’ll keep an eye out for that.
mortendk commentedon Jan 18, 2023
For DDEV i did a
ddev composer self-update
and voila im up and running againComposer 2.2.19
brandonkelly commentedon Feb 7, 2023
Composer 2.2.19 was released a couple days ago, which includes the fix for this.
We just released Craft 3.7.65 and 4.3.8 with that Composer update, so this should be fixed going forward.