LoginSignup
3
2

More than 3 years have passed since last update.

Symfony で composer install --no-dev が失敗する

Last updated at Posted at 2020-12-05

業務でSymfonyを利用していますが、先日、運用環境のデプロイでエラーが発生したので、備忘録を兼ねて投稿します。

  • Symfony 3.0.1

発生したエラー

$ composer install --no-dev

Uncaught exception 'Symfony\Component\Debug\Exception\FatalErrorException' with message 'Error: Uncaught Symfony\Component\Debug\Exception\FatalThrowableError: Fatal error: Class 'Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle' not found in ...

原因

Composer scripts に以下のような記載があり、copmoser install 時に cache:clear が実行されますが、デフォルトでは --env dev で実行されます。

    ...
    "scripts": {
        "post-install-cmd": [
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::prepareDeploymentTarget"
        ],
        "post-update-cmd": [
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::prepareDeploymentTarget"
        ]
    },
    ...

このため、存在しないバンドルに対してアクセスしようとしてしまい、エラーとなってしまいます。

対応方法

今回はデプロイコマンドで composer install していたので、SYMFONY_ENV=prod で実行してあげるだけでした。

SYMFONY_ENV=prod copmoser install --no-dev

手動でキャッシュクリアしている場合は、cache:clear にも --env prod を指定してください。

./bin/console cache:clear --env prod

同じエラーで悩んでいる方がいましたら、ご参考いただければと思います。

参照

3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2