composer icon indicating copy to clipboard operation
composer copied to clipboard

autoload_classmap.php file empty after running composer commands

Open davorminchorov opened this issue 10 years ago • 32 comments

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?

davorminchorov avatar Sep 23 '16 09:09 davorminchorov

The same issue, the same environment and framework. PHP 7.0.11, Composer 1.2.1

SergeySetti avatar Sep 25 '16 06:09 SergeySetti

Discussion about problem by other people https://laracasts.com/discuss/channels/general-discussion/composer-generating-autoload-files-fails

SergeySetti avatar Sep 25 '16 06:09 SergeySetti

The best solution for now - downgrading to Composer 1.2.0

SergeySetti avatar Sep 25 '16 16:09 SergeySetti

I'll try to downgrade it but how can I do that?

davorminchorov avatar Sep 25 '16 16:09 davorminchorov

@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

SergeySetti avatar Sep 25 '16 21:09 SergeySetti

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.

alcohol avatar Sep 26 '16 06:09 alcohol

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.

davorminchorov avatar Sep 26 '16 07:09 davorminchorov

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.

Seldaek avatar Sep 29 '16 06:09 Seldaek

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 avatar Sep 30 '16 17:09 coldlamper

@coldlamper what version do you get installed? Because 1.8.0 has no autoload definitions at all, so that doesn't mean anything.

Seldaek avatar Oct 01 '16 10:10 Seldaek

I think it's 1.8.9

coldlamper avatar Oct 04 '16 17:10 coldlamper

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.

alcohol avatar Oct 04 '16 19:10 alcohol

Sorry it is installing 1.8.0. I believe it should be installing 1.8.9, correct?

coldlamper avatar Oct 04 '16 21:10 coldlamper

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.

Seldaek avatar Oct 05 '16 05:10 Seldaek

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.

coldlamper avatar Oct 05 '16 14:10 coldlamper

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)

stof avatar Oct 05 '16 15:10 stof

For now you can get around this by using the --ignore-platform-reqs flag.

alcohol avatar Oct 06 '16 06:10 alcohol

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.

davorminchorov avatar Oct 06 '16 10:10 davorminchorov

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 avatar Nov 02 '16 08:11 jural

@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.

davorminchorov avatar Nov 04 '16 10:11 davorminchorov