You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Magento 2.2.3升级至2.3.7后产品详情页出现BASE_URL未定义错误求助

Fixing "BASE_URL is not defined" in add-home-breadcrumb.js After Magento 2.2.3 → 2.3.7 Upgrade

Hey there, I’ve dealt with similar Magento upgrade quirks before, so let’s walk through how to fix this BASE_URL undefined error in the new home breadcrumb feature:

1. Fix the Dependency in add-home-breadcrumb.js

The root issue is likely that the new script is trying to use BASE_URL without properly importing the dependency that defines it. Magento 2.3.x prefers using the mage/url module over global variables for URL handling.

Open vendor/magento/module-theme/view/frontend/web/js/view/add-home-breadcrumb.js and update its define block to use mage/url instead of relying on BASE_URL:

define([
    'uiComponent',
    'mage/url'
], function (Component, urlBuilder) {
    'use strict';

    return Component.extend({
        defaults: {
            template: 'Magento_Theme/breadcrumb/home'
        },

        getHomeUrl: function () {
            // Replace BASE_URL with urlBuilder to get the home URL
            return urlBuilder.build('/');
        }
    });
});

2. Flush Caches and Redeploy Static Content

Magento’s static file cache is almost always a culprit after upgrades. Run these commands to clear old assets and regenerate fresh ones:

bin/magento cache:clean
bin/magento cache:flush
bin/magento setup:static-content:deploy -f
bin/magento setup:upgrade

Don’t skip the -f flag—it forces deployment even if you’re using the default Luma/Blank theme.

3. Check for Custom Theme Overrides

If you’re using a custom theme, verify if you’ve overridden the add-home-breadcrumb.js file in app/design/frontend/[Your_Vendor]/[Your_Theme]/Magento_Theme/web/js/view/. If so:

  • Either update your custom file to match the corrected dependency structure above
  • Or delete the custom file entirely to let Magento use the core module’s version

4. Verify Global BASE_URL Loading (Last Resort)

If the above steps don’t work, check if BASE_URL is actually being defined globally:

  1. Open your browser’s console on the product page and type BASE_URL—if it returns undefined, your theme’s head layout might be missing the necessary script to set this variable.
  2. Ensure your theme’s default_head_blocks.xml includes the core theme’s requirejs config:
    <referenceContainer name="head.additional">
        <block class="Magento\Framework\View\Element\Template" name="requirejs-config" template="Magento_Theme::js/requirejs-config.phtml"/>
    </referenceContainer>
    

If none of these fixes resolve the issue, try comparing your vendor/magento/module-theme files against a fresh download of Magento 2.3.7 to ensure no core files were modified during the upgrade.

内容的提问来源于stack exchange,提问作者nshah143

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.30 09:22:49