【问题标题】:Error installing dependencies when deploying to Heroku部署到 Heroku 时安装依赖项时出错
【发布时间】:2019-06-07 04:01:06
【问题描述】:

我正在尝试将我的 Symfony 应用程序部署到 Heroku,但是当我运行命令 git push heroku master 时出现错误:

未捕获的错误:在 /tmp/build_808fab60090f288d282076c72569d1ad/app/AppKernel.php:19 中找不到类“Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle”:19

错误日志:

Generating optimized autoload files 
remote: > Incenteev\ParameterHandler\ScriptHandler::buildParameters 
remote: Creating the "app/config/parameters.yml" file 
remote: > Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::buildBootstrap 
remote: > Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache 
remote: PHP Fatal error: Uncaught Error: Class 'Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle' not found in /tmp/build_808fab60090f288d282076c72569d1ad/app/AppKernel.php:19 
remote: Stack trace: 
remote: #0 /tmp/build_808fab60090f288d282076c72569d1ad/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php(450): AppKernel->registerBundles() 
remote: #1 /tmp/build_808fab60090f288d282076c72569d1ad/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php(116): Symfony\Component\HttpKernel\Kernel->initializeBundles() 
remote: #2 /tmp/build_808fab60090f288d282076c72569d1ad/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php(137): Symfony\Component\HttpKernel\Kernel->boot() 
remote: #3 /tmp/build_808fab60090f288d282076c72569d1ad/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php(124): Symfony\Bundle\FrameworkBundle\Console\Application->registerCommands() 
remote: #4 /tmp/build_808fab60090f288d282076c72569d1ad/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php(90): Symfony\Bundle\Framewor in /tmp/build_808fab60090f288d282076c72569d1ad/app/AppKernel.php on line 19 
remote: Script Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache handling the symfony-scripts event terminated with an exception 
remote: 
remote: 
remote: [RuntimeException] 
remote: An error occurred when executing the "'cache:clear —no-warmup'" command: 
remote: 
remote: 
remote: 
remote: PHP Fatal error: Uncaught Error: Class 'Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle' not found in /tmp/build_808fab60090f288d282076c72569d1ad/app/AppKernel.php:19 
remote: Stack trace: 
remote: #0 /tmp/build_808fab60090f288d282076c72569d1ad/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php(450): AppKernel->registerBundles() 
remote: #1 /tmp/build_808fab60090f288d282076c72569d1ad/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php(116): Symfony\Component\HttpKernel\Kernel->initializeBundles() 
remote: #2 /tmp/build_808fab60090f288d282076c72569d1ad/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php(137): Symfony\Component\HttpKernel\Kernel->boot() 
remote: #3 /tmp/build_808fab60090f288d282076c72569d1ad/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php(124): Symfony\Bundle\FrameworkBundle\Console\Application->registerCommands() 
remote: #4 /tmp/build_808fab60090f288d282076c72569d1ad/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php(90): Symfony\Bundle\Framewor in /tmp/build_808fab60090f288d282076c72569d1ad/app/AppKernel.php on line 19 
remote: 
remote: 
remote: install [--prefer-source] [--prefer-dist] [--dry-run] [--dev] [--no-dev] [--no-custom-installers] [--no-autoloader] [--no-scripts] [--no-progress] [--no-suggest] [-v|vv|vvv|--verbose] [-o|--optimize-autoloader] [-a|--classmap-authoritative] [--apcu-autoloader] [--ignore-platform-reqs] [--] [<packages>]... 
remote: 
remote: ! WARNING: There was a class not found error in your code 
remote: 
remote: ! ERROR: Dependency installation failed! 

我的AppKernel::registerBundles()

    public function registerBundles()
    {
        $bundles = [
            new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
            new Symfony\Bundle\SecurityBundle\SecurityBundle(),
            new Symfony\Bundle\TwigBundle\TwigBundle(),
            new Symfony\Bundle\MonologBundle\MonologBundle(),
            new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
            new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
            new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
            new AppBundle\AppBundle(),
            new Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle(),
            new Knp\DoctrineBehaviors\Bundle\DoctrineBehaviorsBundle(),
            new Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle(),
            new Stof\DoctrineExtensionsBundle\StofDoctrineExtensionsBundle(),
        ];

        if (in_array($this->getEnvironment(), ['dev', 'test'], true)) {
            $bundles[] = new Symfony\Bundle\DebugBundle\DebugBundle();
            $bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
            $bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();

            if ('dev' === $this->getEnvironment()) {
                $bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
                $bundles[] = new Symfony\Bundle\WebServerBundle\WebServerBundle();
            }
        }

        return $bundles;
    }

composer.json(“需要”块)

{
    "require": {
        "php": ">=5.5.9",
        "doctrine/doctrine-bundle": "^1.6",
        "doctrine/doctrine-migrations-bundle": "^1.3",
        "doctrine/orm": "^2.5",
        "incenteev/composer-parameter-handler": "^2.0",
        "knplabs/doctrine-behaviors": "^1.4",
        "sensio/distribution-bundle": "^5.0.19",
        "sensio/framework-extra-bundle": "^3.0.2",
        "stof/doctrine-extensions-bundle": "^1.3",
        "symfony/monolog-bundle": "^3.1.0",
        "symfony/polyfill-apcu": "^1.0",
        "symfony/swiftmailer-bundle": "^2.3.10",
        "symfony/symfony": "3.3.*",
        "twig/twig": "^1.0||^2.0"
    },
    "require-dev": {
        "doctrine/doctrine-fixtures-bundle": "^3.0",
        "sensio/generator-bundle": "^3.0",
        "symfony/phpunit-bridge": "^3.0"
    }
}

我需要做什么?

【问题讨论】:

  • @yivi 是的,非常感谢,它有效。但是现在我收到另一个错误,例如:``` PHP Warning: count(): Parameter must be an array or an object that implement Countable in /tmp/build_c1c44af237acd11b7e49f6c98f7d82b5/vendor/symfony/monolog-bundle/DependencyInjection/Configuration.php on line第654章
  • 这是一个不同的问题,与这个无关。您可能需要提出一个新问题,但如果您花一些时间进行测试和重新研究,这样您的问题就会包含所有必要的细节,这可能会更好。如果我的回答解决了 this 问题,请记住您可以接受它。欢迎使用 Stack Overflow。

标签: php symfony heroku doctrine-orm heroku-cli


【解决方案1】:

你已经安装了“doctrine/doctrine-fixtures-bundle”用于开发:

"require-dev": {
        "doctrine/doctrine-fixtures-bundle": "^3.0",
        "sensio/generator-bundle": "^3.0",
        "symfony/phpunit-bridge": "^3.0"
    },

但正在尝试在生产中使用它。

当您部署应用程序时,heroku 正在使用 --no-dev 标志安装作曲家依赖项,这会跳过在 require-dev 中声明的包。

当应用程序尝试运行AppKernel::registerBundles() 时,它会尝试实例化Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle,但未安装该包。

您应该删除第 19 行 (new Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle(),) 并将其添加到以下块中的某处:

if (in_array($this->getEnvironment(), ['dev', 'test'], true)) {
            $bundles[] = new Symfony\Bundle\DebugBundle\DebugBundle();
            $bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
            $bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
            $bundles[] = new Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle();
           // ^^^^^ this line here

这是检查环境是dev 还是test,并且仅在这些环境中尝试使用这些包。

【讨论】:

    猜你喜欢
    • 2014-10-16
    • 1970-01-01
    • 2014-10-16
    • 2015-10-27
    • 2014-09-10
    • 2016-08-23
    • 2021-01-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多