-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Description
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?
Activity
SergeySetti commentedon Sep 25, 2016
The same issue, the same environment and framework.
PHP 7.0.11, Composer 1.2.1
SergeySetti commentedon Sep 25, 2016
Discussion about problem by other people https://laracasts.com/discuss/channels/general-discussion/composer-generating-autoload-files-fails
SergeySetti commentedon Sep 25, 2016
The best solution for now - downgrading to Composer 1.2.0
davorminchorov commentedon Sep 25, 2016
I'll try to downgrade it but how can I do that?
SergeySetti commentedon Sep 25, 2016
@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
alcohol commentedon Sep 26, 2016
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.
davorminchorov commentedon Sep 26, 2016
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.
Seldaek commentedon Sep 29, 2016
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.
coldlamper commentedon Sep 30, 2016
I can reproduce an empty autoload_classmap.php file using
for composer.php
and Composer v1.2.1 and PHP 7.0.8
Seldaek commentedon Oct 1, 2016
@coldlamper what version do you get installed? Because 1.8.0 has no autoload definitions at all, so that doesn't mean anything.
coldlamper commentedon Oct 4, 2016
I think it's 1.8.9
alcohol commentedon Oct 4, 2016
It would be nice if you could take the time to check and confirm. Cause the difference is quite significant.
coldlamper commentedon Oct 4, 2016
Sorry it is installing 1.8.0. I believe it should be installing 1.8.9, correct?
7 remaining items
spiritix commentedon Nov 16, 2016
I can confirm this problem, multiple of our developers faced it within the last weeks. Sometimes we could solve it by deleting the
autoload_classmap.php
file, sometimes by reloading Vagrant, sometimes we couldn't get it working at all. It's not a Laravel problem, it's caused by Vagrant on Windows, specifically by the winnfsd/vagrant-winnfsd plugin. Thefile_put_contents
insrc/Composer/Autoload/AutoloadGenerator.php:273
mentioned by @jural does actually work, it returns the number of written bytes like expected. However, the file is still empty after the write operation finishes. This confirms the whole problem being related to the underlying file system. If you configure composer to keep the vendor dir outside of the scope managed by winnfsd ("vendor-dir": "~/composer/"
), everything works fine. The winnfsd plugin is known for being quite buggy in general, so I don't think something in composer can be done to solve this problem.luispabon commentedon Jan 11, 2017
Not a vagrant problem, I just got this running native on Linux and PHP 7.1.
andrei930 commentedon Feb 25, 2017
In my case (using Homestead) this seems to be fixed by removing type: "nfs" from the folders section in Homestead.yaml.
spiritix commentedon Feb 25, 2017
@andrei930 Yes that solves the problem, but without NFS the VM is significantly slower, so that's not really a solution.
andrei930 commentedon Feb 27, 2017
Apparently I was using an outdated version of vagrant-winnfsd. For me it's fixed by updating to the latest version (1.3.1).
Edit: Nevermind, it still fails after a while (?). A workaround is to halt the machine, kill the NFS server and start the vagrant again.
YOzaz commentedon Apr 5, 2018
Anybody found a "proper" solution for this? Halting / killing is kind of hacky.
spiritix commentedon Apr 5, 2018
You can try to use SMB instead of NFS, I am not really aware of the consequences though. Otherwise, I am happy to share the script we ended up with you guys:
Just put that in a bash file on your host machine and execute it once NFS crashed.
Still a hackish solution, but what shall we do :)
YOzaz commentedon Apr 5, 2018
@spiritix that's exactly what we're doing as well, but I thought maybe
winnfsd
developers came up with a better solution.Alternative option would be
composer dumpautoload
(withoutoptimize
flag).It's a clearly NFS mount problem (I've tried experimenting with NFS mount option, which helped a little), as it looks like it runs out of memory?
Non-NFS mount is not an option I think, it would be the same as downgrading to Windows 98 just because Windows 10 freezes once in a month.
spiritix commentedon Apr 5, 2018
@YOzaz Already reported that to the
winnfsd
developers (winnfsd/vagrant-winnfsd#104), maybe you could file an issue as well.huasio commentedon May 16, 2018
@spiritix Damn, I also encountered this problem, based on your recommended solution, is in the local new bash file, the script writing, run it, as I so, operation is still running
NFS
.jartaud commentedon May 29, 2018
@szlwl what?
jantomicky commentedon Aug 19, 2018
Had the exact same problem.
Windows 10, Version 1803, Build 17134.228
Vagrant 2.1.0
VirtualBox 5.2.12
WinNFSd 1.3.1
Laravel Homestead (not sure about the version, probably 7.6, but it shouldn't really matter).
Not using NFS isn't really a solution for me, as it increases page load times from ~2 sec to ~10 sec, sometimes even more.
Seems to be solved by setting these NFS mount options:
I hear that UDP isn't ideal, but it works; on TCP the VM would just freeze on me after ~15 minutes of inactivity, never to recover.
BTW, another and probably related issue, after running
gulp
three and more times to minimize the JavaScript sources, I got a 0 byte file as a result along with a NFS server errorNo such file or directory IO
as mentioned here: winnfsd/vagrant-winnfsd#104 (comment) and only reloading vagrant & the NFS server solved it. Turned out to be an issue with Windows Defender, probably an exclusive file lock / race condition issue.Excluding the whole synchronized folder from the Windows Defender "workspace" seems to do the trick, at least up till now it has – might work in this case for you too.
Also, since then I updated all the tools to their current versions (Vagrant 2.1.2, VirtualBox 5.2.16, WinNFSd 1.4.0, Homestead 7.14.2) and now I'm having zero issues, so I recommend updating everything too.