vincent15000's avatar

Warning: Ambiguous class resolution

Hello,

I get this warning while generating optimized autoload files.

Warning: Ambiguous class resolution, "League\Flysystem\Local\LocalFilesystemAdapterTest" was found in both "/var/www/meeplesperdusaurillac/vendor/league/flysystem-local/LocalFilesystemAdapterTest.php" and "/var/www/meeplesperdusaurillac/vendor/league/flysystem/src/Local/LocalFilesystemAdapterTest.php", the first will be used.

I never get it in the past.

Do you get it too ?

Is there anything to do ?

Thanks for your help.

V

0 likes
7 replies
LaryAI's avatar
Level 58

Sure! Here’s a solution to the "Warning: Ambiguous class resolution" message you are seeing:


The warning

Warning: Ambiguous class resolution, "League\Flysystem\Local\LocalFilesystemAdapterTest" was found in both "/var/www/meeplesperdusaurillac/vendor/league/flysystem-local/LocalFilesystemAdapterTest.php" and "/var/www/meeplesperdusaurillac/vendor/league/flysystem/src/Local/LocalFilesystemAdapterTest.php", the first will be used.

means that Composer found two files that define the same class. This typically happens when:

  • You have vendor packages (in this case Flysystem) where the same files/classes exist in two places (perhaps after package upgrades/changes, or leftover files).
  • Composer is not sure which one to use, so it picks the first, but this can cause strange bugs.

Why did this happen?

  • It often occurs after dependencies have changed (e.g. league/flysystem 2.x/3.x and league/flysystem-local as of v3 are separate packages), and files from older dependencies weren’t cleaned up.
  • Or, there is some misconfiguration where both packages are installed.

How to fix

1. Clean your vendor directory and re-install

Sometimes, leftover files after dependency changes cause this. To fix:

rm -rf vendor
rm composer.lock
composer install

(If you don’t want to delete composer.lock, you can just do composer install after deleting vendor. But deleting both is a good reset.)

This will remove any old files and re-install only what's required per your composer.json.


2. Check your composer.json for conflicting dependencies

Check if you have both league/flysystem and league/flysystem-local listed, and ensure you’re using compatible versions. As of Flysystem v3, LocalFilesystemAdapter is part of league/flysystem-local.

Example for Flysystem 3.x:

"require": {
    "league/flysystem": "^3.0",
    "league/flysystem-local": "^3.0"
}

If you're using Flysystem 2.x, you only need:

"require": {
    "league/flysystem": "^2.0"
}

3. Remove old files

Sometimes, files can linger in vendor/league/flysystem/ or vendor/league/flysystem-local/ after upgrades. After the clean in step 1, it should be resolved. If not, check your vendor directory manually for .php files that shouldn’t exist.


4. Regenerate Autoload Files

After cleaning, re-run:

composer dump-autoload -o

Summary

99% of the time running:

rm -rf vendor composer.lock
composer install
composer dump-autoload -o

...will solve this warning.

If it does not, double-check your composer.json for duplicate/conflicting package entries, and ensure all packages are updated to compatible versions.


Let me know if you have follow-up questions!

tykus's avatar

Why do you require the separate league/flysystem-local package in addition to league/flysystem (which already has the Local Filesystem Adapter available?

1 like
vincent15000's avatar

I don't require any additional package ... I don't have done anything to install it.

vincent15000's avatar
"require": {
    "php": "^8.2",
    "fakerphp/faker": "^1.24",
    "inertiajs/inertia-laravel": "^3.0",
    "laravel/fortify": "^1.25",
    "laravel/framework": "^12.0",
    "laravel/sanctum": "^4.0",
    "laravel/tinker": "^2.10.1",
    "staudenmeir/eloquent-has-many-deep": "^1.21",
    "tightenco/ziggy": "^2.6"
},
"require-dev": {
    "laravel/envoy": "^2.10",
    "laravel/pail": "^1.2.2",
    "laravel/pint": "^1.13",
    "laravel/sail": "^1.43",
    "mockery/mockery": "^1.6",
    "nunomaduro/collision": "^8.6",
    "pestphp/pest": "*",
    "pestphp/pest-plugin-laravel": "^4.0",
    "plannr/laravel-fast-refresh-database": "^1.2"
},
composer why league/flysystem-local
laravel/framework v12.55.1 requires league/flysystem-local (^3.25.1) 
league/flysystem  3.33.0   requires league/flysystem-local (^3.0.0)  
DigitalArtisan's avatar
Level 2

This directory should not exist:

var/www/meeplesperdusaurillac/vendor/league/flysystem/src/Local

I'd delete vendor/league/flysystem then run composer again.

1 like
vincent15000's avatar

@tykus @digitalartisan

The problem came from the installation process of the dependencies.

I forgot to install php8.4-zip extension and the zip packages couldn't be unzipped, so they were retrieved from git.

I don't know why this process generated the error, but now all works perfectly.

1 like

Please or to participate in this conversation.