使用开发依赖项在 Heroku 上部署时,尝试从命名空间“Symfony\Bundle\WebProfilerBundle”加载类“WebProfilerBundle”

dan*_*lev 5 php heroku symfony heroku-ci symfony4

我们在 Heroku 上托管了一个 Symfony 4.3 Web 应用程序。这是一个新设置,我们从未设法让开发模式正常工作。网上有很多类似的问题,但没有一个能解决我们在这里面临的确切症状。

该项目是使用命令行创建的:

composer create-project symfony/website-skeleton appName
Run Code Online (Sandbox Code Playgroud)

让我澄清一点:我们不希望改变“开发”“刺”

我们需要能够在开发模式下使用该应用程序,以便根据此处针对 Symfony 4.3文章“如何自定义错误页面”利用 PHP 的错误调试

$ php bin/console about
 -------------------- ----------------------------------------------------
  Symfony
 -------------------- ----------------------------------------------------
  Version              4.3.5
  End of maintenance   01/2020
  End of life          07/2020
 -------------------- ----------------------------------------------------
  Kernel
 -------------------- ----------------------------------------------------
  Type                 App\Kernel
  Environment          dev
  Debug                true
  Charset              UTF-8
  Cache directory      ./var/cache/dev (12.1 MiB)
  Log directory        ./var/log (13 KiB)
 -------------------- ----------------------------------------------------
  PHP
 -------------------- ----------------------------------------------------
  Version              7.3.10
  Architecture         64 bits
  Intl locale          n/a
  Timezone             Europe/Berlin (2019-10-28T15:48:05+01:00)
  OPcache              false
  APCu                 false
  Xdebug               false
 -------------------- ----------------------------------------------------
  Environment (.env)
 -------------------- ----------------------------------------------------
  APP_ENV              dev
 *just a few removed before posting for privacy*
 -------------------- ----------------------------------------------------
Run Code Online (Sandbox Code Playgroud)

如果我们从“dev”环境更改为“prod”环境,应用程序可以工作,但我们无法以我们希望的方式看到错误。我们可以使用下面的命令(但这不是我们在这里试图解决的问题)来使用“Symfony Var Dumper Server”。我们不想使用这种方法。

./bin/console server:dump
Run Code Online (Sandbox Code Playgroud)

看来,我们可能缺少的依赖,但composer updatecomposer installcomposer dump-autoload没有解决任何问题。

还要注意消息“您是否忘记了另一个命名空间的“使用”语句?在 /tmp/build_a45354eb0ee7b20dd7ec870ed4fb1980/src/Kernel.php:23 中“- 主存储库中的 WebProfilerBundle 是否有可能损坏?

为了进一步帮助了解情况,以下是composer.json文件

{
    "type": "project",
    "license": "proprietary",
    "require": {
        "php": "^7.1.3",
        "ext-ctype": "*",
        "ext-iconv": "*",
        "phpmailer/phpmailer": "^6.1",
        "sensio/framework-extra-bundle": "^5.5",
        "symfony/asset": "4.3.*",
        "symfony/console": "4.3.*",
        "symfony/dotenv": "4.3.*",
        "symfony/expression-language": "4.3.*",
        "symfony/flex": "^1.3.1",
        "symfony/form": "4.3.*",
        "symfony/framework-bundle": "4.3.*",
        "symfony/http-client": "4.3.*",
        "symfony/intl": "4.3.*",
        "symfony/mailer": "4.3.*",
        "symfony/monolog-bundle": "^3.1",
        "symfony/orm-pack": "^1.0",
        "symfony/process": "4.3.*",
        "symfony/security-bundle": "4.3.*",
        "symfony/serializer-pack": "*",
        "symfony/swiftmailer-bundle": "^3.1",
        "symfony/translation": "4.3.*",
        "symfony/twig-bundle": "4.3.*",
        "symfony/twig-pack": "^1.0",
        "symfony/validator": "4.3.*",
        "symfony/web-link": "4.3.*",
        "symfony/webpack-encore-bundle": "^1.7",
        "symfony/yaml": "4.3.*"
    },
    "require-dev": {
        "symfony/debug-bundle": "4.3.*",
        "symfony/debug-pack": "*",
        "symfony/maker-bundle": "^1.14",
        "symfony/profiler-pack": "^1.0",
        "symfony/test-pack": "*",
        "symfony/web-profiler-bundle": "4.3.*",
        "symfony/web-server-bundle": "4.3.*"
    },
    "config": {
        "preferred-install": {
            "*": "dist"
        },
        "sort-packages": true
    },
    "autoload": {
        "psr-4": {
            "App\\": "src/"
        }
    },
    "autoload-dev": {
        "psr-4": {
            "App\\Tests\\": "tests/"
        }
    },
    "replace": {
        "paragonie/random_compat": "2.*",
        "symfony/polyfill-ctype": "*",
        "symfony/polyfill-iconv": "*",
        "symfony/polyfill-php71": "*",
        "symfony/polyfill-php70": "*",
        "symfony/polyfill-php56": "*"
    },
    "scripts": {
        "auto-scripts": {
            "cache:clear": "symfony-cmd",
            "assets:install %PUBLIC_DIR%": "symfony-cmd"
        },
        "post-install-cmd": [
            "@auto-scripts"
        ],
        "post-update-cmd": [
            "@auto-scripts"
        ]
    },
    "conflict": {
        "symfony/symfony": "*"
    },
    "extra": {
        "symfony": {
            "allow-contrib": false,
            "require": "4.3.*"
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我们的障碍:尝试使用dev模式部署到 heroku 。

git push heroku master
Run Code Online (Sandbox Code Playgroud)

失败并显示以下消息:

remote:        Executing script cache:clear [KO]
remote:         [KO]
remote:        Script cache:clear returned with error code 255
remote:        !!  PHP Fatal error:  Uncaught Symfony\Component\Debug\Exception\ClassNotFoundException: Attempted to load class "WebProfilerBundle" from namespace "Symfony\Bundle\WebProfilerBundle".
remote:        !!  Did you forget a "use" statement for another namespace? in /tmp/build_a45354eb0ee7b20dd7ec870ed4fb1980/src/Kernel.php:23
remote:        !!  Stack trace:
remote:        !!  #0 /tmp/build_a45354eb0ee7b20dd7ec870ed4fb1980/vendor/symfony/http-kernel/Kernel.php(429): App\Kernel->registerBundles()
remote:        !!  #1 /tmp/build_a45354eb0ee7b20dd7ec870ed4fb1980/vendor/symfony/http-kernel/Kernel.php(130): Symfony\Component\HttpKernel\Kernel->initializeBundles()
remote:        !!  #2 /tmp/build_a45354eb0ee7b20dd7ec870ed4fb1980/vendor/symfony/framework-bundle/Console/Application.php(159): Symfony\Component\HttpKernel\Kernel->boot()
remote:        !!  #3 /tmp/build_a45354eb0ee7b20dd7ec870ed4fb1980/vendor/symfony/framework-bundle/Console/Application.php(65): Symfony\Bundle\FrameworkBundle\Console\Application->registerCommands()
remote:        !!  #4 /tmp/build_a45354eb0ee7b20dd7ec870ed4fb1980/vendor/symfony/console/Application.php(149): Symfony\Bundle\FrameworkBundle\Cons in /tmp/build_a45354eb0ee7b20dd7ec870ed4fb1980/src/Kernel.php
on line 23
remote:        !!
remote:        Script @auto-scripts was called via post-install-cmd
remote:  !     WARNING: There was a class not found error in your code
remote:
remote:  !     ERROR: Dependency installation failed!
remote:  !
remote:  !     The 'composer install' process failed with an error. The cause
remote:  !     may be the download or installation of packages, or a pre- or
remote:  !     post-install hook (e.g. a 'post-install-cmd' item in 'scripts')
remote:  !     in your 'composer.json'.
remote:  !
remote:  !     Typical error cases are out-of-date or missing parts of code,
remote:  !     timeouts when making external connections, or memory limits.
remote:  !
remote:  !     Check the above error output closely to determine the cause of
remote:  !     the problem, ensure the code you're pushing is functioning
remote:  !     properly, and that all local changes are committed correctly.
remote:  !
remote:  !     For more information on builds for PHP on Heroku, refer to
remote:  !     https://devcenter.heroku.com/articles/php-support
remote:  !
remote:  !     REMINDER: the following warnings were emitted during the build;
remote:  !     check the details above, as they may be related to this error:
remote:  !     - There was a class not found error in your code
remote:
remote:  !     Push rejected, failed to compile PHP app.
remote:
remote:  !     Push failed
Run Code Online (Sandbox Code Playgroud)

我们目前不知道如何安装或验证 Symfony 4.3 的捆绑包确实存在和运行 - 这个方向的想法可能会有所帮助,但不仅如此。

php bin/console config:dump-reference

Available registered bundles with their extension alias if available
====================================================================

 ---------------------------- ------------------------
  Bundle name                  Extension alias
 ---------------------------- ------------------------
  DebugBundle                  debug
  DoctrineBundle               doctrine
  DoctrineCacheBundle          doctrine_cache
  DoctrineMigrationsBundle     doctrine_migrations
  FrameworkBundle              framework
  MakerBundle                  maker
  MonologBundle                monolog
  SecurityBundle               security
  SensioFrameworkExtraBundle   sensio_framework_extra
  SwiftmailerBundle            swiftmailer
  TwigBundle                   twig
  TwigExtraBundle              twig_extra
  WebProfilerBundle            web_profiler
  WebServerBundle              web_server
  WebpackEncoreBundle          webpack_encore
 ---------------------------- ------------------------

 // Provide the name of a bundle as the first argument of this command to dump its default configuration. (e.g.
 // config:dump-reference FrameworkBundle)
 //
 // For dumping a specific option, add its path as the second argument of this command. (e.g.
 // config:dump-reference FrameworkBundle profiler.matcher to dump the
 // framework.profiler.matcher configuration)
Run Code Online (Sandbox Code Playgroud)

yiv*_*ivi 6

Heroku 不会在您的 dyno 中安装开发依赖项。这在此处记录:构建行为

具体来说,heroku 将运行:

composer install --no-dev --prefer-dist --optimize-autoloader --no-interaction
Run Code Online (Sandbox Code Playgroud)

理论上来说,heroku 是像代码一样用于生产,所以开发依赖不属于那里。通常,这些依赖项只会安装在开发人员的机器上,而不是安装在任何已部署的应用程序实例上。

如果你真的需要这对部署的代码,我想你应该承认这不是发展的依赖,但依赖定期和他们移动require-devrequire