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.
phpunit
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.
Terminal
composer install --no-interaction --prefer-distAdd Faker explicitly if it is missing
If require-dev lost the package, add it back so factories resolve.
Terminal
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.
Related guides
Laravel PHPUnit "Class Tests\... not found" (autoload-dev) in CIFix Laravel PHPUnit "Class Tests\... not found" in CI - the Tests namespace is under autoload-dev, so install…
Laravel "Class ... not found" (composer dump-autoload) in CIFix Laravel "Error: Class ... not found" in CI - the autoloader map is stale, so run composer dump-autoload (…
Laravel "php artisan test" vs vendor/bin/phpunit mismatch in CIFix Laravel CI where php artisan test and vendor/bin/phpunit behave differently - artisan test boots the fram…