No idea why I haven't noticed this before, but my project's production error logs contain lots of lines of the following exception:
staging.ERROR: Symfony\Component\Debug\Exception\FatalThrowableError: Class 'Faker\Factory' not found in /home/project/vendor/laravel/framework/src/Illuminate/Database/DatabaseServiceProvider.php:78
DatabaseServiceProvider
clearly requires the faker package, while it's only installed as dev package (and even optional to include in any project).
$this->app->singleton(FakerGenerator::class, function ($app) {
return FakerFactory::create($app['config']->get('app.faker_locale', 'en_US'));
});
Was investigating why the beanstalkd daemons on production stopped executing jobs and what's causing timeouts when trying to access the site. Not sure if related though.
In composer.json:
"require-dev": {
"fzaninotto/faker": "^1.6"
},
Deploy to production (which only installs everything under require
, excluding dev packages and thus faker too).
Hi,
Same error with Laravel 5.4.27.
Can't deploy with "composer install --no-dev
" because no artisan's commands will work.
Faker should only be used in development, looks like you use faker somewhere in your code in production, that causes the container to create an instance of FakerGenerator
for you and thus call the closure.
Make sure you're not using faker anywhere in your production code, and if you must, just move faker to the require
section.
Themsaid, that's in the core.
The piece of code only register the service to the container. Until a code ask to resolve FakerGenerator
you shouldn't have this issue. So @themsaid comment is correct. Somewhere in your code (or packages) that you load attempt to resolve which is not possible .
related: #18163 #14131 #14130 #9723
Effectively I found a line that make EloquentFactory, that needs FakerFactory ...
Removed this line permits to move "fzaninotto/faker" in composer "require" section.
This is also happening in Laravel 5.6
In DatabaseServiceProvider.php line 78:
Class 'Faker\Factory' not found
Search the issues for "faker production" to see past discussions on this topic.
If you have installed package nwidart/laravel-modules
and run composer install --no-dev
make sure your .env config APP_ENV= is set to production otherwise you'll encounter this issue if it's set to local. Hope that helps someone
the @wmandai did not work for me. Why is it now required ?
Most helpful comment
If you have installed package
nwidart/laravel-modules
and runcomposer install --no-dev
make sure your .env config APP_ENV= is set to production otherwise you'll encounter this issue if it's set to local. Hope that helps someone