cancel
Showing results for 
Search instead for 
Did you mean: 

Uncaught ReferenceError: $ is not defined magento 2.3.2

Uncaught ReferenceError: $ is not defined magento 2.3.2

My new theme is store in \app\design\frontend\<your_vendor_name>/<your_theme_name>\ 

and i have added requirejs-config.js file in above location with follwoing contents:

 var config = {
map: {
'*': {
megamenu: 'js/megamenu.min'
}
},
shim: {
'megamenu': {
deps: ['$']
}
}
};

-----------------------------------------------

my megamenu.js file uses $ for initiating jquery. How can i solve jquery reference issue?

1.png

 

 

2 REPLIES 2

Re: Uncaught ReferenceError: $ is not defined magento 2.3.2

hello @ruta 

 

in your megamenu.js file you need to define jquery like below code

define(
    ['jquery'],
    function($) {
       /*
        * your code
        */
});

If my answer is useful Click kudos & Accept as Solution

Re: Uncaught ReferenceError: $ is not defined magento 2.3.2

Basically $ is an alias of jQuery() so when you try to call/access it before declaring the function, it will endup throwing this $ is not defined error . This usually indicates that jQuery is not loaded and JavaScript does not recognize the $. Even with $(document).ready , $ is still going to be undefined because jquery hasn't loaded yet.

 

To solve this error:

 

Load the jQuery library at the beginning of all your javascript files/scripts which uses $ or jQuery, so that $ can be identified in scripts .

 

There can be multiple other reasons for this issue:

 

  • Path to jQuery library you included is not correct
  • The jQuery library file is corrupted
  • Working offline
  • Conflict with Other Libraries