15

I am trying to deploy a laravel project on forge and i am getting the below exception :

Symfony\Component\Debug\Exception\FatalErrorException]  
Class 'Faker\Factory' not found     

I have the faker reference in require-dev in composer.json!

composer.json file

{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"type": "project",
"require": {
    "php": ">=5.5.9",
    "laravel/framework": "5.1.*",
    "tymon/jwt-auth": "0.5.*",
    "dingo/api": "1.0.x@dev"
},
"require-dev": {
    "fzaninotto/faker": "~1.5",
    "mockery/mockery": "0.9.*",
    "phpunit/phpunit": "~4.0",
    "phpspec/phpspec": "~2.1",
    "laracasts/testdummy": "1.*",
    "laracasts/generators": "^1.1"
},
"autoload": {
    "classmap": [
        "database"
    ],
    "psr-4": {
        "App\\": "app/"
    }
},
"autoload-dev": {
    "classmap": [
        "tests/TestCase.php"
    ]
},
"scripts": {
    "post-install-cmd": [
        "php artisan clear-compiled",
        "php artisan optimize"
    ],
    "pre-update-cmd": [
        "php artisan clear-compiled"
    ],
    "post-update-cmd": [
        "php artisan optimize"
    ],
    "post-root-package-install": [
        "php -r \"copy('.env.example', '.env');\""
    ],
    "post-create-project-cmd": [
        "php artisan key:generate"
    ]
},
"config": {
    "preferred-install": "dist"
}

}

Deployment script in Forge:

git pull origin master 
composer install --no-interaction --no-dev --prefer-dist
php artisan migrate --force
php artisan db:seed --class="StaticDataSeeder"

I was able to deploy the same project locally with out any problem and composer update on forge also runs successfully and i can see the faker package getting downloaded.

Please let me know if i am missing something.

vthallam
  • 551
  • 2
  • 8
  • 20

3 Answers3

40

There is a clear conflict that explains your problem:

  1. You've added the "fzaninotto/faker" package to the require-dev section.

  2. You're running the deployment composer install command with the --no-dev option which explicitly prohibits installing the packages listed in require-dev.

So the solution is either to move the package to the require section or remove the --no-dev option when deploying.

Bogdan
  • 43,166
  • 12
  • 128
  • 129
  • Thanks a lot! Removed the '--no-dev' option and that did the trick. :) – vthallam Sep 26 '15 at 20:49
  • 6
    Glad I could help. **Small tip:** If you're using the `fzaninotto/faker` package to generate seed data (since I see you're running a seeder within the deployment process), I suggest you move it to the `require` section, because by removing the `--no-dev` option, you're installing `phpunit/phpunit` and all the other packages listed in `require-dev` on your production server, which is not really needed. – Bogdan Sep 26 '15 at 21:00
  • Thanks for the tip! I will move it to the require column then :) – vthallam Sep 27 '15 at 00:59
  • Manually change ```composer.lock```? Forge blocked deployment: "Verifying lock file contents can be installed on current platform. Warning: The lock file is not up to date with the latest changes in composer.json...Required package 'fakerphp/faker' is not present in lock file." – JimB814 Aug 05 '23 at 12:57
0

I have same problem on heroku deployment i think it same, i fix with

  1. moving "fzaninotto/faker": "~1.4" from "require-dev" to "require" in composer.json and composer.lock
  2. composer install
  3. composer update
  4. git add
  5. git commit
  6. git push heroku

if you don't use heroku as deployment don't run from step 4-6

Ricky Anwar
  • 109
  • 1
  • 5
0

Run the next command:

composer install

And the problem should go away