I'm implementing a custom store switcher in my custom theme.

Block template is as follow:

<?php if (count($block->getStores())>1): ?>
    <?php $id = $block->getIdModifier() ? '-' . $block->getIdModifier() : ''?>

    <span><?php echo $block->escapeHtml($block->getStoreName()) ?></span>


    <?php foreach ($block->getStores() as $_lang): ?>
        <?php if ($_lang->getId() != $block->getCurrentStoreId()): ?>
            <span class="view-<?php echo $block->escapeHtml($_lang->getCode()); ?> switcher-option">
                <a href="#" data-post='<?php /* @escapeNotVerified */ echo $block->getTargetStorePostData($_lang); ?>'>
                    <?php echo $block->escapeHtml($_lang->getName()) ?>
        <?php endif; ?>
    <?php endforeach; ?>

<?php endif; ?>

The link to new store is correctly displayed so I guess the xml stuff is OK, but on click I receive the following error:

section-config.js:33 Uncaught TypeError: Cannot read property '*' of undefined(…)

The generated html looks like the following:

<span class="view-it switcher-option">
  <a href="#" data-post="{"action":"http:\/\/test.mysite.eu\/stores\/store\/switch\/","data":{"___store":"it","uenc":"aHR0cDovL3Rlc3QuZnJhZ2lhY29tb21pbGFuby5ldS8,"}}">
  • Have you run deploy command and remove var folder? Commented Nov 30, 2016 at 9:36
  • nope XD I'll do it and follow up
    – davideghz
    Commented Nov 30, 2016 at 9:36
  • I just ran sudo php bin/magento setup:static-content:deploy w/o any luck. Why shall I remove var folder? What exactly should I remove?
    – davideghz
    Commented Nov 30, 2016 at 9:40
  • you have to remove all content of var folder Commented Nov 30, 2016 at 9:41
  • 1
    @davideghz did you get the solution ? Commented Feb 28, 2017 at 10:01

5 Answers 5


I had the same problem and found out that these two blocks where not called any more due to customizations in the theme.

The two blocks are per default added in the <referenceContainer name="content"> of vendor/magento/module-customer/view/frontend/layout/default.xml.

Try re-adding these blocks in your layout.xml:

<block name="customer.section.config" class="Magento\Customer\Block\SectionConfig"
<block name="customer.customer.data"
  • I have the same Problem but the Blocks are rendered. I guess it's because I am in a requireJs method while calling the cart reload method, but the JS is executed before the block is rendered. Can I depend on any js module to avoid this?
    – bpoiss
    Commented Dec 1, 2017 at 8:00
  • 1
    Just had this exact same problem.. while using github.com/SnowdogApps/magento2-theme-blank-sass (Magento 2.2.6). Adding the two above blocks fixed the problem. Thanks Commented Nov 3, 2018 at 21:57

On our project we fixed it in the section-config.js file in the method getAffectedSections (which is where our error was).
We replaced the last line:

return _.union(_.toArray(actions), _.toArray(sections['*']));

By the following one:

return (sections && sections.length > 0) ? _.union(_.toArray(actions), _.toArray(sections['*'])) : {};

To actually returns an empty array when no section is affected.

  • Does your solution work well?
    – Jared Chu
    Commented Dec 17, 2018 at 3:58
  • 1
    Yes it was a functionning workaround, but IIRC, the real root of our issue was a slight misuse of the JS API in the end. It did not make this fix unrelevant, it's still a protection to ensures the code keeps running and does not stop here, in not critical error cases.
    – Flinth
    Commented Dec 18, 2018 at 14:38
  • 1
    Thanks, It's working..
    – Ravi Soni
    Commented May 22, 2019 at 6:54
  • It is working for me also. But in some categories when I change store view, after store view is changed I get invalid form key. Please refresh page. No form is there though....I am confused
    – G. G.
    Commented Jan 25, 2020 at 22:56
  • 1
    Working fine :) thanks you very much. Commented Jun 7, 2020 at 18:12

Ran across the same issue even though the customer.section.config and customer.customer.data were properly loaded into the page.

In my case however it happened because an extension tried to trigger a section-reload too early (before section-config.js was loaded with the right configuration).

Managed to solve it by adding a breakpoint in getAffectedSections of section-config.js and checking the url variable. Then moved the extension JS to load after the customer.section.config block:

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
        <move element="extension.js.block" destination="content" after="customer.section.config"/> 

In our case this was a bit of code in a default template which was loading the customer-data.js file after it had already been called on the success page.

We found file: vendor/magento/module-checkout/view/frontend/templates/success.phtml

was loading this code:

    ], function (customerData) {
        var sections = ['cart'];
        customerData.reload(sections, true);

Removing this code fixed it, which we did by creating a copy of this file in our theme templates directory and removing the offending code snippet.

You can use Chrome Dev tools to find out where the error was happening and then just before in that file on your local dev add in a console.trace(); call to establish what was calling the function which is throwing the error in the console. Follow the chain to where you are loading things improperly.


In my case, someone has removed the "columns" container like below from the custom page layout

<referenceContainer name="columns" remove="true" />

Removing this line makes it working and the error is gone.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.