Website runs locally, but not on server. ComposerAutoloaderInit not found

I have a website running perfectly on my local valet or plain php -S.
But when I upload the website to the server, I get the following error:

Fatal error: Uncaught Error:
Class ComposerAutoloaderInitc23f66edbdd29a34175a5670c4a18687 not found in ./vendor/autoload.php:7
Stack trace:
#0 ./kirby/bootstrap.php(21): include()
#1 ./index.php(3): require('kirby/bootstrap.php')
#2 {main} thrown in ./vendor/autoload.php on line 7

(I replaced my server path with ./)

I checked more then 50 times that PHP versions are both the same (8.0.12) and that the whole website (including content, kirby folder, vendor folder, …) is 100% identical. That weird class ComposerAutoloaderInit... is also present.

I have Kirby 3.6, used composer to install and my index.php looks like that:

require __DIR__ . '/kirby/bootstrap.php';
echo (new Kirby())->render();

I also checked the file permissions on the server, it’s all 777. I deleted and reinstalled everything 20 times. There is really nothing left I could imagine causing this issue.

Has anyone any idea how to solve it?

Okay, I deleted everything (kirby, vendor, composer files, …) and reinstalled everything. It now works.
The only thing that is different compared to before, is that I removed the following from the composer.json:

"config": {
    "optimize-autoloader": true
  }

Very frustrating, I just spent 4 sunday hours on this issue.

The same thing now happened to me with another website.
I had to delete the vendor folder as well as composer.lock, remove the "optimize-autoloader": true setting and run composer install again.

Hmm, somehow this keeps happening every time I upload stuff to the server. Has anyone had the same problem?

"optimize-autoloader": true shouldn’t cause this issue on its own.

Are you running composer install on the server or before the upload? Which method do you use to upload the files to the server?