Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

neilcarpenter's avatar

Composer generating autoload files fails

I've pulled in laravel using new laravel app

Then i've tried pulling in laracasts/flash using composer require laracasts/flash

Things seem to be going ok untill it gets to "Generating autoload files" I'm then getting an error..

Installation failed, reverting ./composer.json to its original content.
[ErrorException]
Argument 1 passed to Composer\Autoload\ClassLoader::addClassMap() must be of the type array, integer given, called in phar:///usr/local/bin/composer/src/Composer/Autoload/AutoloadGenerator.php on line 723 and defined

I have no idea why this has started happening, it happens whenever composer gers to generating autoload files....

Can anyone help me sort this out please?

0 likes
27 replies
neilcarpenter's avatar

my vendor/composer/autoload_classmap.php is empty....

I'll be honest I don't really know what any of these autoload files are/do .....

Should there be something in that file?

neilcarpenter's avatar

I haven't made any changes to my composer.json file... here it is...

{
    "name": "laravel/laravel",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "license": "MIT",
    "type": "project",
    "require": {
        "php": ">=5.6.4",
        "laravel/framework": "5.3.*"
    },
    "require-dev": {
        "fzaninotto/faker": "~1.4",
        "mockery/mockery": "0.9.*",
        "phpunit/phpunit": "~5.0",
        "symfony/css-selector": "3.1.*",
        "symfony/dom-crawler": "3.1.*"
    },
    "autoload": {
        "classmap": [
            "database"
        ],
        "psr-4": {
            "App\\": "app/"
        }
    },
    "autoload-dev": {
        "classmap": [
            "tests/TestCase.php"
        ]
    },
    "scripts": {
        "post-root-package-install": [
            "php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "php artisan key:generate"
        ],
        "post-install-cmd": [
            "Illuminate\\Foundation\\ComposerScripts::postInstall",
            "php artisan optimize"
        ],
        "post-update-cmd": [
            "Illuminate\\Foundation\\ComposerScripts::postUpdate",
            "php artisan optimize"
        ]
    },
    "config": {
        "preferred-install": "dist"
    }
}
tomopongrac's avatar

what you get when you execute this command

composer dump-autoload
tomopongrac's avatar

Try remove values from classmap and execute above command

{
    "name": "laravel/laravel",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "license": "MIT",
    "type": "project",
    "require": {
        "php": ">=5.6.4",
        "laravel/framework": "5.3.*"
    },
    "require-dev": {
        "fzaninotto/faker": "~1.4",
        "mockery/mockery": "0.9.*",
        "phpunit/phpunit": "~5.0",
        "symfony/css-selector": "3.1.*",
        "symfony/dom-crawler": "3.1.*"
    },
    "autoload": {
        "classmap": [
        ],
        "psr-4": {
            "App\\": "app/"
        }
    },
    "autoload-dev": {
        "classmap": [
        ]
    },
    "scripts": {
        "post-root-package-install": [
            "php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "php artisan key:generate"
        ],
        "post-install-cmd": [
            "Illuminate\\Foundation\\ComposerScripts::postInstall",
            "php artisan optimize"
        ],
        "post-update-cmd": [
            "Illuminate\\Foundation\\ComposerScripts::postUpdate",
            "php artisan optimize"
        ]
    },
    "config": {
        "preferred-install": "dist"
    }
}
neilcarpenter's avatar

Nope, same problem. I don't think it's a problem with the json file... I've tried the below composer.json file and it still errors...

{
    "name": "laravel/laravel",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "license": "MIT",
    "type": "project",
}

I also tried what you suggested with the same error

dgpro's avatar

Hi, I've got exactly the same error after updating composer last night. And here is a full error log:

PHP Fatal error:  Uncaught TypeError: Argument 1 passed to Composer\Autoload\ClassLoader::addClassMap() must be of the type array, integer given, called in phar:///usr/local/bin/composer/src/Composer/Autoload/AutoloadGenerator.php on line 723 and defined in phar:///usr/local/bin/composer/vendor/composer/ClassLoader.php:91
Stack trace:
#0 phar:///usr/local/bin/composer/src/Composer/Autoload/AutoloadGenerator.php(723): Composer\Autoload\ClassLoader->addClassMap(1)
#1 phar:///usr/local/bin/composer/src/Composer/Autoload/AutoloadGenerator.php(286): Composer\Autoload\AutoloadGenerator->getStaticFile('879a2d5dbb534de...', '/var/www/vendor...', '/var/www/vendor', '/var/www', 50600)
#2 phar:///usr/local/bin/composer/src/Composer/Installer.php(291): Composer\Autoload\AutoloadGenerator->dump(Object(Composer\Config), Object(Composer\Repository\InstalledFilesystemRepository), Object(Composer\Package\RootPackage), Object(Composer\Installer\InstallationManager), '/var/www/vendor...', false)
#3 phar:///usr/local/bin/composer/src/Composer/Com in phar:///usr/local/bin/composer/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 phar:///usr/local/bin/composer/src/Composer/Autoload/AutoloadGenerator.php on line 723 and defined in phar:///usr/local/bin/composer/vendor/composer/ClassLoader.php on line 91

TypeError: Argument 1 passed to Composer\Autoload\ClassLoader::addClassMap() must be of the type array, integer given, called in phar:///usr/local/bin/composer/src/Composer/Autoload/AutoloadGenerator.php on line 723 in phar:///usr/local/bin/composer/vendor/composer/ClassLoader.php on line 91

Call Stack:
    0.0001     352568   1. {main}() /usr/local/bin/composer:0
    0.0072     569464   2. require('phar:///usr/local/bin/composer/bin/composer') /usr/local/bin/composer:25
    0.0281    3086384   3. Composer\Console\Application->run() phar:///usr/local/bin/composer/bin/composer:43
    0.0301    3323128   4. Symfony\Component\Console\Application->run() phar:///usr/local/bin/composer/src/Composer/Console/Application.php:104
    0.0307    3398344   5. Composer\Console\Application->doRun() phar:///usr/local/bin/composer/vendor/symfony/console/Application.php:123
    0.1722    7771488   6. Symfony\Component\Console\Application->doRun() phar:///usr/local/bin/composer/src/Composer/Console/Application.php:231
    0.1722    7771488   7. Symfony\Component\Console\Application->doRunCommand() phar:///usr/local/bin/composer/vendor/symfony/console/Application.php:192
    0.1723    7771488   8. Symfony\Component\Console\Command\Command->run() phar:///usr/local/bin/composer/vendor/symfony/console/Application.php:847
    0.1725    7773992   9. Composer\Command\InstallCommand->execute() phar:///usr/local/bin/composer/vendor/symfony/console/Command/Command.php:259
    0.1744    8005096  10. Composer\Installer->run() phar:///usr/local/bin/composer/src/Composer/Command/InstallCommand.php:135
    0.3641    9902224  11. Composer\Autoload\AutoloadGenerator->dump() phar:///usr/local/bin/composer/src/Composer/Installer.php:291
    4.0135   10621272  12. Composer\Autoload\AutoloadGenerator->getStaticFile() phar:///usr/local/bin/composer/src/Composer/Autoload/AutoloadGenerator.php:286
    4.0178   10699952  13. Composer\Autoload\ClassLoader->addClassMap() phar:///usr/local/bin/composer/src/Composer/Autoload/AutoloadGenerator.php:723

And looks like the problem is here:

#0 phar:///usr/local/bin/composer/src/Composer/Autoload/AutoloadGenerator.php(723): Composer\Autoload\ClassLoader->addClassMap(1)

But I can't seems to figure out how to debug it and find the cause. Any ideas?

dgpro's avatar

This is so strange but 20 minutes late after repeated composer update the problem has gone...

1 like
neilcarpenter's avatar

No clue yet @DenMayDay I haven't been able to solve the problem. I'm using virtualbox with php 5.6 and centos 6. Think I might have to destroy my box and completely remove composer, rebuild it and try a clean install of everything. I'll give it a go today at some point.

dgpro's avatar

@neilcarpenter I'm using vagrant as well and after running vagrant reload --provision the problem has gone.

neilcarpenter's avatar

I've got 5.6.25 which maybe why i;m still failing. I've tried vagrant reload --provision

I'll try updating to 5.6.4 (as per the laravel docs) - and see if that helps.

Melcus's avatar

Did you find a fix for this? I'm getting the same in a clean project

neilcarpenter's avatar

Nope - I couldn't upgrade my php version to 5.6.4 on my box either because it's not available from the repo it gets dragged in from....

What version of PHP are you running @Melcus ?

dgpro's avatar

Got this issue again and to fix it I had to delete composer autoload files and then regenerate them again (vagrant, ubuntu, laravel 5)

cd /var/www/
rm -rf vendor/composer/autoload_*
composer dumpautoload
11 likes
tbence's avatar

I had the same problem and deleted the autoload files. Now it works.

(Homestead, Ubuntu 16.04LTS, PHP 7.0.14)

orrd's avatar

I had this problem with my Vagrant box (under Windows) and nothing fixed it until I removed the 'type: "nfs"' option in my Homestead.yaml file for the folder mount.

It was pretty crazy, any attempt to write to the file named "vendor/composer/autoload_classmap.php" would result in a 0 length file. I could create a "autoload_classmap2.php" just fine, but not "autoload_classmap.php". Even deleting the file and trying again did nothing. Even re-provisioning the box didn't fix it.

But anyway, it's some kind of strange issue with the Vagrant box mapped folders.

4 likes
ncamm's avatar

@orrd removing nfs kills the performance of syncying though. I rebooted, ran composer dump-autoload then composer update and it fixed my issue.

1 like
juslintek's avatar

Without nfs vagrant is very slow, with nfs composer problems. Someone damn fix this. Or my but will split. :-((( Tears falling...

PetarVukmanovic's avatar

yeeeah, here to confirm that NFS strikes again. Hope we'll get a good windows fix for this soon. :(

2 likes
rmff's avatar

Windows host? Kill NFS for Windows and reboot Homestead to restart NFS / mount folders.

1 like
MT6's avatar

The problem disappeared once I stopped using composer inside the vagrant box and directly into the mounted folder on the host machine.

Please or to participate in this conversation.