Uncaught Reference Error $ is not defined

JKP84
Excursionist
16 0 10

I am receiving the above error when i inspect my site. it appears to be referring to the following (the line in bold/red) in my theme.js file:

var adjustStyleAndPosition = theme.Helpers.debounce(function() {
styleDropdowns(document.querySelectorAll(selectors.siteNavHasDropdown));
positionFullWidthDropdowns();
$(selectors.multicurrencySelector).on('change', function() {
$(this)
.parents('form')
.submit();
});
}, 50);

and this one:

var later = function() {
timeout = null;
if (!immediate) func.apply(context, args);
};

can anyone help me out with fixing this?

Thanks

 

Replies 7 (7)
gina-gregory
Shopify Expert
711 49 185

That error means that jQuery is not loaded on the site when that code runs. This could either be because jQuery is not added to the theme at all or it is deferred and loading AFTER this code runs.

JKP84
Excursionist
16 0 10

Thank you @gina-gregory - is this a big issue that will affect the site functioning?

gina-gregory
Shopify Expert
711 49 185

Yes, any code dependent on jQuery will not work if the jQuery library is not present when it tries to run.

designrepo
New Member
18 0 0

Same Problem.

Did you get any solution?

Please let me know.

IttantaTech
Shopify Partner
510 55 92

Hello , @designrepo 

Please add this line of code :- <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>

into your theme.liquid file after <head>

Thanks,
Ittanta Technologies Pvt. Ltd. | Shopify Expert
If reply is helpful, please Like and Accept Solution.
To hire us, contact us at info@ittanta.com
designrepo
New Member
18 0 0

Thank you.!

creigmalta
New Member
4 0 0

If you are using any script file and getting "Uncaught ReferenceError: x is not defined " which means ‘x’ is either a variable or a method which you are trying to use before declaring it using var keyword. This means that there is a non-existent variable referenced somewhere. This variable needs to be declared, or you need to make sure it is available in your current script or scope otherwise , it will endup throwing this ‘x’ is not defined error . This usually indicates that your library is not loaded and JavaScript does not recognize the ‘x’.

To solve this error: Load your library at the beginning of all your scripts.

There can be multiple other reasons for this issue:

  • Conflict with Other Libraries
  • Path to your library included is not correct
  • Llibrary file is corrupted
  • Working offline (when you use CDN)