Laravel "Class Faker\... not found" in factories in CI
Model factories call Faker to generate data. fakerphp/faker ships as a dev dependency, so a composer install --no-dev in the test job removes it and any factory usage fails with "Class Faker\Factory not found." Install dev deps for tests.
What this error means
Seeding or a test that uses a factory fails with "Error: Class \"Faker\Factory\" not found" or "Class \"Faker\Generator\" not found", though it works locally.
Error: Class "Faker\Factory" not found
in /vendor/laravel/framework/.../FakerConcern.phpCommon causes
Installed with --no-dev, removing Faker
Faker is under require-dev. Installing without dev dependencies leaves factories unable to resolve the Faker classes.
A production-optimized vendor cache in the test job
Restoring a --no-dev vendor directory into the test job omits Faker entirely.
How to fix it
Install dev dependencies in the test job
- Run
composer installwithout--no-dev. - Confirm
fakerphp/fakerappears in the installed packages. - Re-run so factories can call Faker.
composer install --no-interaction --prefer-distAdd Faker explicitly if it is missing
If require-dev lost the package, add it back so factories resolve.
composer require fakerphp/faker --devHow to prevent it
- Never use
--no-devin the job that runs factories or tests. - Keep fakerphp/faker in require-dev.
- Do not reuse a production vendor cache for tests.