试图加载类“WebProfilerBundle"来自命名空间“Symfony\Bundle\WebProfilerBundle"使用开发依赖项在 Heroku 上部署时 [英] Attempted to load class "WebProfilerBundle" from namespace "Symfony\Bundle\WebProfilerBundle" when deploying on Heroku using development dependencies
问题描述
我们在 Heroku 上托管了一个 Symfony 4.3 Web 应用程序.这是一个新设置,我们从未设法让开发模式正常工作.网上有很多类似的问题,但没有一个能解决我们在这里面临的确切症状.
We have a Symfony 4.3 web application hosted on Heroku. This is a new setup and we never managed to have the dev mode to work correctly. There are plenty of similar issues online but none fixes the exact symptoms we are facing here.
项目是用命令行创建的:
The project was created with a command line:
composer create-project symfony/website-skeleton appName
让我澄清一下:我们不想将从dev"改为prod"
Let me clarify that: we do not want to change from "dev" to "prod"
我们需要能够在开发模式下使用应用程序,以便根据 文章如何为 Symfony 4.3 自定义错误页面"
We need to be able to use the application in dev mode in order to take advantage of error debugging for PHP as per the article "How to Customize Error Pages" for Symfony 4.3 here
$ 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*
-------------------- ----------------------------------------------------
如果我们从 'dev' 环境更改为 'prod' 环境,应用程序可以工作,但我们无法以我们希望的方式看到错误.我们可以使用下面的命令(但这不是我们在这里试图解决的问题)来使用Symfony Var Dumper Server".我们不想使用这种方法.
If we change from 'dev' to 'prod' environment the application works but we cannot see the errors the way we wish to. We could use the command below (but this is not the point we are trying to solve here) in order to use "Symfony Var Dumper Server". We do not want to use this method.
./bin/console server:dump
似乎我们可能缺少一个依赖项,但是 composer update
和 composer install
和 composer dump-autoload
没有解决任何问题.
It seems that we might be missing a dependency but composer update
and composer install
and composer dump-autoload
did not solve anything.
另请注意消息您是否忘记了另一个命名空间的使用"语句?在/tmp/build_a45354eb0ee7b20dd7ec870ed4fb1980/src/Kernel.php:23" - WebProfilerBundle 是否可能损坏在主存储库中?
Also note the message "Did you forget a "use" statement for another namespace? in /tmp/build_a45354eb0ee7b20dd7ec870ed4fb1980/src/Kernel.php:23" - Is it possible that the WebProfilerBundle is broken in the master repository?
为了进一步帮助理解情况,下面是composer.json
文件
To further help understand the situation, below is the composer.json
file
{
"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.*"
}
}
}
我们的障碍:尝试使用 dev
模式部署到 heroku.
Our obstacle: trying to deploy to heroku using dev
mode.
git push heroku master
失败并显示以下消息:
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
我们目前不知道如何安装或验证捆绑包确实存在并且适用于 Symfony 4.3 - 这个方向的想法可能会有所帮助,但不仅如此.
We currently do not know how to install or verify that bundles are indeed present and operational for Symfony 4.3 - ideas in this direction might help but not only.
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)
推荐答案
Heroku 不会在您的 dyno 中安装开发依赖项.这在此处记录:构建行为.
Heroku will not install dev dependencies in your dyno. This is documented here: Build behaviour.
具体来说,heroku 将运行:
Specifically, heroku will run:
composer install --no-dev --prefer-dist --optimize-autoloader --no-interaction
理论认为 heroku 像代码一样用于生产,因此开发依赖项不属于那里.通常,这些依赖项只会安装在开发人员的机器上,而不是安装在任何已部署的应用程序实例上.
The theory goes that heroku is for production like code, so development dependencies do not belong there. Usually, these dependencies would only be installed on the developers' machines, not on any deployed application instance.
如果你真的在部署的代码上需要这个,我想你应该承认这不是开发依赖而是常规依赖,并将它们从 require-dev
移到 require
.
If you really need this on deployed code, I guess you should admit this are not development dependencies but regular dependencies, and move them from require-dev
to require
.
这篇关于试图加载类“WebProfilerBundle"来自命名空间“Symfony\Bundle\WebProfilerBundle"使用开发依赖项在 Heroku 上部署时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!