Magento 2.4.6-p3升级至2.4.7-p2前端出现Auth类不存在异常
升级Magento 2.4.6-p3至2.4.7-p2时前端出现「Class 'Auth' does not exist」异常的解决方案
环境信息
- Magento版本:从2.4.6-p3升级至2.4.7-p2
- PHP版本:8.2
异常详情
1 exception(s): Exception #0 (ReflectionException): Class "Auth" does not exist
完整异常堆栈:
#1 Magento\Framework\Code\Reader\ClassReader->getConstructor() called at [vendor/magento/framework/ObjectManager/Definition/Runtime.php:50] #2 Magento\Framework\ObjectManager\Definition\Runtime->getParameters() called at [vendor/magento/framework/ObjectManager/Factory/Compiled.php:100] #3 Magento\Framework\ObjectManager\Factory\Compiled->create() called at [vendor/magento/framework/ObjectManager/ObjectManager.php:73] #4 Magento\Framework\ObjectManager\ObjectManager->get() called at [vendor/magento/module-customer/view/frontend/templates/js/customer-data.phtml:14] #5 include() called at [vendor/magento/framework/View/TemplateEngine/Php.php:67] #6 Magento\Framework\View\TemplateEngine\Php->render() called at [vendor/magento/framework/Interception/Interceptor.php:58] #7 Magento\Framework\View\TemplateEngine\Php\Interceptor->___callParent() called at [vendor/magento/framework/Interception/Interceptor.php:138] #8 Magento\Framework\View\TemplateEngine\Php\Interceptor->Magento\Framework\Interception\{closure}() called at [vendor/magento/framework/Interception/Interceptor.php:153] #9 Magento\Framework\View\TemplateEngine\Php\Interceptor->___callPlugins() called at [generated/code/Magento/Framework/View/TemplateEngine/Php/Interceptor.php:23] #10 Magento\Framework\View\TemplateEngine\Php\Interceptor->render() called at [vendor/magento/framework/View/Element/Template.php:263] #11 Magento\Framework\View\Element\Template->fetchView() called at [vendor/magento/framework/View/Element/Template.php:293] #12 Magento\Framework\View\Element\Template->_toHtml() called at [vendor/magento/framework/View/Element/AbstractBlock.php:1128] #13 Magento\Framework\View\Element\AbstractBlock->Magento\Framework\View\Element\{closure}() called at [vendor/magento/framework/View/Element/AbstractBlock.php:1132] #14 Magento\Framework\View\Element\AbstractBlock->_loadCache() called at [vendor/magento/framework/View/Element/AbstractBlock.php:676] #15 Magento\Framework\View\Element\AbstractBlock->toHtml() called at [vendor/magento/framework/View/Layout.php:578] #16 Magento\Framework\View\Layout->_renderBlock() called at [vendor/magento/framework/View/Layout.php:555] #17 Magento\Framework\View\Layout->renderNonCachedElement() called at [vendor/magento/framework/View/Layout.php:510] #18 Magento\Framework\View\Layout->renderElement() called at [vendor/magento/framework/View/Layout.php:606] #19 Magento\Framework\View\Layout->_renderContainer() called at [vendor/magento/framework/View/Layout.php:557] #20 Magento\Framework\View\Layout->renderNonCachedElement() called at [vendor/magento/framework/View/Layout.php:510] #21 Magento\Framework\View\Layout->renderElement() called at [vendor/magento/framework/View/Layout.php:606] #22 Magento\Framework\View\Layout->_renderContainer() called at [vendor/magento/framework/View/Layout.php:557] #23 Magento\Framework\View\Layout->renderNonCachedElement() called at [vendor/magento/framework/View/Layout.php:510] #24 Magento\Framework\View\Layout->renderElement() called at [vendor/magento/framework/View/Layout.php:606] #25 Magento\Framework\View\Layout->_renderContainer() called at [vendor/magento/framework/View/Layout.php:557] #26 Magento\Framework\View\Layout->renderNonCachedElement() called at [vendor/magento/framework/View/Layout.php:510] #27 Magento\Framework\View\Layout->renderElement() called at [vendor/magento/framework/View/Layout.php:606] #28 Magento\Framework\View\Layout->_renderContainer() called at [vendor/magento/framework/View/Layout.php:557] #29 Magento\Framework\View\Layout->renderNonCachedElement() called at [vendor/magento/framework/View/Layout.php:510] #30 Magento\Framework\View\Layout->renderElement() called at [vendor/magento/framework/View/Layout.php:606] #31 Magento\Framework\View\Layout->_renderContainer() called at [vendor/magento/framework/View/Layout.php:557] #32 Magento\Framework\View\Layout->renderNonCachedElement() called at [vendor/magento/framework/View/Layout.php:510] #33 Magento\Framework\View\Layout->renderElement() called at [vendor/magento/framework/View/Layout.php:606] #34 Magento\Framework\View\Layout->_renderContainer() called at [vendor/magento/framework/View/Layout.php:557] #35 Magento\Framework\View\Layout->renderNonCachedElement() called at [vendor/magento/framework/View/Layout.php:510] #36 Magento\Framework\View\Layout->renderElement() called at [vendor/magento/framework/View/Layout.php:975] #37 Magento\Framework\View\Layout->getOutput() called at [vendor/magento/framework/Interception/Interceptor.php:58] #38 Magento\Framework\View\Layout\Interceptor->___callParent() called at [vendor/magento/framework/Interception/Interceptor.php:138] #39 Magento\Framework\View\Layout\Interceptor->Magento\Framework\Interception\{closure}() called at [vendor/magento/framework/Interception/Interceptor.php:153] #40 Magento\Framework\View\Layout\Interceptor->___callPlugins() called at [generated/code/Magento/Framework/View/Layout/Interceptor.php:41] #41 Magento\Framework\View\Layout\Interceptor->getOutput() called at [vendor/magento/framework/View/Result/Page.php:260] #42 Magento\Framework\View\Result\Page->render() called at [vendor/magento/framework/View/Result/Layout.php:171] #43 Magento\Framework\View\Result\Layout->renderResult() called at [vendor/magento/framework/Interception/Interceptor.php:58] #44 Magento\Framework\View\Result\Page\Interceptor->___callParent() called at [vendor/magento/framework/Interception/Interceptor.php:138] #45 Magento\Framework\View\Result\Page\Interceptor->Magento\Framework\Interception\{closure}() called at [vendor/magento/framework/Interception/Interceptor.php:153] #46 Magento\Framework\View\Result\Page\Interceptor->___callPlugins() called at [generated/code/Magento/Framework/View/Result/Page/Interceptor.php:32] #47 Magento\Framework\View\Result\Page\Interceptor->renderResult() called at [vendor/magento/framework/App/Http.php:120] #48 Magento\Framework\App\Http->launch() called at [vendor/magento/framework/Interception/Interceptor.php:58] #49 Magento\Framework\App\Http\Interceptor->___callParent() called at [vendor/magento/framework/Interception/Interceptor.php:138] #50 Magento\Framework\App\Http\Interceptor->Magento\Framework\Interception\{closure}() called at [vendor/magento/module-application-performance-monitor/Plugin/ApplicationPerformanceMonitor.php:38] #51 Magento\ApplicationPerformanceMonitor\Plugin\ApplicationPerformanceMonitor->aroundLaunch() called at [vendor/magento/framework/Interception/Interceptor.php:135] #52 Magento\Framework\App\Http\Interceptor->Magento\Framework\Interception\{closure}() called at [vendor/magento/framework/Interception/Interceptor.php:153] #53 Magento\Framework\App\Http\Interceptor->___callPlugins() called at [generated/code/Magento/Framework/App/Http/Interceptor.php:23] #54 Magento\Framework\App\Http\Interceptor->launch() called at [vendor/magento/framework/App/Bootstrap.php:264] #55 Magento\Framework\App\Bootstrap->run() called at [pub/index.php:30]
已执行的命令
bin/magento s:up; bin/magento s:d:c; bin/magento s:s:d -f; bin/magento c:f
解决方案
从堆栈信息可知,错误触发点在customer-data.phtml模板调用ObjectManager->get('Auth'),但Magento核心不存在无命名空间的Auth类,以下是针对性修复步骤:
1. 检查并修复自定义模板
- 查看主题或自定义模块中是否存在修改后的模板:
app/design/frontend/[你的主题厂商]/[主题名]/Magento_Customer/templates/js/customer-data.phtml - 将该模板与Magento核心原版模板(
vendor/magento/module-customer/view/frontend/templates/js/customer-data.phtml)对比,找到调用Auth的代码行,替换为完整命名空间的类(比如\Magento\Customer\Model\Auth,需根据实际业务需求确认正确类) - 若无需自定义模板,直接删除该文件,让系统使用核心模板
2. 排查第三方模块或自定义代码
- 执行以下命令搜索所有引用
Auth的文件:grep -r "Auth" app/code vendor --include="*.php" --include="*.phtml" - 找到所有未使用完整命名空间调用
Auth的代码,替换为对应的完整类名 - 若发现是第三方模块导致,检查该模块是否有兼容Magento 2.4.7-p2和PHP 8.2的版本,升级或替换该模块
3. 彻底清理并重新部署
执行以下命令清理生成文件、编译代码并刷新缓存:
rm -rf generated/code generated/metadata var/view_preprocessed var/page_cache var/cache bin/magento setup:upgrade bin/magento setup:di:compile bin/magento setup:static-content:deploy -f bin/magento cache:flush
4. 排查PHP 8.2兼容性问题
- 临时禁用所有第三方模块,验证问题是否消失:
bin/magento module:disable $(bin/magento module:status --enabled | grep -v Magento | grep -v "^$") - 若问题解决,逐个启用模块,找到引发问题的模块,联系开发者获取兼容版本,或自行修复代码中的PHP 8.2兼容性问题
内容的提问来源于stack exchange,提问作者Shubham Nigam
相关产品推荐
相关产品推荐

