Have your say in Community Polls: What was/is your greatest motivation to start your own business?

Uncaught Reference Error $ is not defined

Uncaught Reference Error $ is not defined

JKP84
Excursionist
32 0 12

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 10 (10)

gina-gregory
Shopify Partner
742 51 213

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
32 0 12

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

gina-gregory
Shopify Partner
742 51 213

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

designrepo
Excursionist
48 0 4

Same Problem.

Did you get any solution?

Please let me know.

IttantaTech
Shopify Partner
525 55 103

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
Excursionist
48 0 4

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)

 

ryeung316
Shopify Partner
4 0 1

This worked like a charm, thank you!

LukasMali
Visitor
1 0 0

I was trying to fix this problem for a whole day. Thank you very much!

Brade277
Shopify Partner
1 0 0

Love it mate. was tryin to fix it for 3 hours. Hats off buddy.