autoload_classmap.php file empty after running composer commands
Hey,
I work on a Laravel project and whenever I run composer install / update, dump-autoload or any php artisan commands, everything works fine for the first time, but when I run another composer / artisan command after that, I get the following error:
PHP Fatal error: Uncaught TypeError: Argument 1 passed to Composer\Autoload\ClassLoader::addClassMap() must be of the type array, integer given, called in /var/www/html/vendor/composer/autoload_real.php on line 38 and defined in /var
/www/html/vendor/composer/ClassLoader.php:91
Stack trace:
#0 /var/www/html/vendor/composer/autoload_real.php(38): Composer\Autoload\ClassLoader->addClassMap(1)
#1 /var/www/html/vendor/autoload.php(7): ComposerAutoloaderInitab0ba58f39538bb9f0cac5f548fa5488::getLoader()
#2 /var/www/html/bootstrap/autoload.php(17): require('/var/www/html/v...')
#3 /var/www/html/artisan(16): require('/var/www/html/b...')
#4 {main}
thrown in /var/www/html/vendor/composer/ClassLoader.php on line 91
Fatal error: Uncaught TypeError: Argument 1 passed to Composer\Autoload\ClassLoader::addClassMap() must be of the type array, integer given, called in /var/www/html/vendor/composer/autoload_real.php on line 38 and defined in /var/www/
html/vendor/composer/ClassLoader.php:91
Stack trace:
#0 /var/www/html/vendor/composer/autoload_real.php(38): Composer\Autoload\ClassLoader->addClassMap(1)
#1 /var/www/html/vendor/autoload.php(7): ComposerAutoloaderInitab0ba58f39538bb9f0cac5f548fa5488::getLoader()
#2 /var/www/html/bootstrap/autoload.php(17): require('/var/www/html/v...')
#3 /var/www/html/artisan(16): require('/var/www/html/b...')
#4 {main}
thrown in /var/www/html/vendor/composer/ClassLoader.php on line 91
I noticed that the autoload_classmap.php file is empty, so for a quick temporary fix, I deleted the composer folder and just run composer install.
I've deleted the vendor folder completely and rerun composer install but that seems to work temporary. I still get the same error on the second composer / artisan command.
I am using PHP 7.0.10 and Vagrant + Docker as my environment. I use a local composer.phar file inside the application container.
When I run composer self-update I get:
You are already using composer version 1.2.1 (stable channel).
The weird part is that my colleague is using the same docker environment and he doesn't have this problem. Also, this happens to this project only.
If you need any more information, let me know.
Any ideas what might be the problem?
The same issue, the same environment and framework. PHP 7.0.11, Composer 1.2.1
Discussion about problem by other people https://laracasts.com/discuss/channels/general-discussion/composer-generating-autoload-files-fails
The best solution for now - downgrading to Composer 1.2.0
I'll try to downgrade it but how can I do that?
@Rufflesaurus , just composer self-update 1.2.0
Or you can replace your composer bin with https://getcomposer.org/download/1.2.0/composer.phar
Do you have a way to reproduce this without artisan? I'm not going to install laravel global plugins just to get this working. If you do not have any other way to reproduce this, then I think we can conclude that this is not a composer bug, but a laravel bug instead.
I think it's hard to reproduce this problem because it only happens from time to time, usually when the composer dump-autoload -o is running. It also happens when I install a new package / do an update for new packages.
It's ok for now, I'll report back if it happens again.
OK closing this for now but please come back to us with details if you find a way to reproduce it reliably. Downgrading to 1.2.0 is not a solution btw, if downgrading really helps, then we need to figure out what broke in 1.2.1 and fix it.
I can reproduce an empty autoload_classmap.php file using
{
"require": {
"authorizenet/authorizenet": "~1.8"
}
}
for composer.php and Composer v1.2.1 and PHP 7.0.8
@coldlamper what version do you get installed? Because 1.8.0 has no autoload definitions at all, so that doesn't mean anything.
I think it's 1.8.9
I think it's 1.8.9
It would be nice if you could take the time to check and confirm. Cause the difference is quite significant.
Sorry it is installing 1.8.0. I believe it should be installing 1.8.9, correct?
1.8.9 has a bunch of requirements like it needs ext-xmlwriter and ext-simplexml, maybe you don't have those so it is downgrading to 1.8.0 which does not have the requirements. Try requiring 1.8.9 explicitly and it should tell you why it is not installable.
Using "authorizenet/authorizenet": "1.8.9"
Problem 1
- Installation request for authorizenet/authorizenet 1.8.3.3 -> satisfiable by authorizenet/authorizenet[1.8.3.3].
- authorizenet/authorizenet 1.8.3.3 requires php ~5.3 -> your PHP version (7.0.8) does not satisfy that requirement.
next step: contact the authorizenet maintainers to ask them to allow installing their package on PHP 7 (their PHP requirement tells composer that it cannot be used on PHP 7)
For now you can get around this by using the --ignore-platform-reqs flag.
It looks like the problem is back once I ran composer update to update the packages. Before that, I tried running composer dump-autoload -o just to see if it will fail again, but it was magically fixed for some reason.
I didn't use any commands for a few days and just before I started using them again I ran composer update and something brought the problem back.
Still trying to figure out what might be causing the problem but I have a hard time reproducing it so you can test it on your own.
I had the same error. I think it is not related to composer.
My configuration is: Windows host, vagrant with Debian quest and nfs sharing enabled, composer 1.2.1.
I debugged this and noticed that composer in src/Composer/Autoload/AutoloadGenerator.php:273 wants to save content to existing file autoload_classmap.php:
file_put_contents($targetDir.'/autoload_classmap.php', $classmapFile);
After this operation (called with success) content of this file is still empty. I removed this file (vendor/composer/autoload_classmap.php) and call again composer.phar dump-autoload. File was created with content and problem was solved.
I think problem is related to permissions of this file or problems with sharing files between host -> quest in vagrant... I hope I will help someone :)
@jural I tried deleting all of the autoload files inside the composer folder and running composer dump-autoload -o as you suggested but the problem is still there.