Skip to content

JavaScript not executed when it has Magento_Customer/js/customer-data dependencia in define

I have a JS file like this:

define([
        'jquery',
        'underscore',
        'matchMedia',
        'text!ajaxcart/template/modal-slide.html',
        'text!ajaxcart/template/modal-popup.html',
        'Magento_Customer/js/customer-data',
        'Magento_Catalog/product/view/validation',
        'Magento_Ui/js/modal/modal',
        'mage/translate'
    ], function($, _, mediaCheck, _slideTpl, _popupTpl, customerData) {
...
    }

But for some reason, it is not entered into the code in function until I remove “Magento_Customer/js/customer-data”. I mean, if I change it to this:

define([
        'jquery',
        'underscore',
        'matchMedia',
        'text!ajaxcart/template/modal-slide.html',
        'text!ajaxcart/template/modal-popup.html',
        //'Magento_Customer/js/customer-data',
        'Magento_Catalog/product/view/validation',
        'Magento_Ui/js/modal/modal',
        'mage/translate'
    ], function($, _, mediaCheck, _slideTpl, _popupTpl/*, customerData*/) {
...
    }

It works fine, except in the part of the code where I need the customerData variable that returns an obvious error:

Uncaught ReferenceError: customerData is not defined.

But if I keep it as in the start, all file is ignored and not executed. I don’t know why the reference Magento_Customer/js/customer-data is causing this problem. I don’t see any error in the browser console or log. Any idea?

UPDATE: I detected this same error happened with another JS file but with mage/cookies dependency:

require([
        "jquery",
        "Magento_Ui/js/modal/modal",
        "mage/cookies",
        "jquery/jquery.cookie",
        'Magento_Customer/js/model/customer'
    ],function($, modal,cookie,jscookie,customer) {
      ...
    }

Same behavior, if I remove mage/cookies, it works, but when is present, the code is not running.