Uncaught Reference Error $ is not defined

Topic summary

  • Issue: “Uncaught ReferenceError: $ is not defined” occurs in theme.js where jQuery ($) is used (e.g., .on(‘change’) on a selector). $ is the jQuery alias.

  • Cause: jQuery isn’t loaded when the code runs—either not included in the theme or loaded after dependent scripts (deferred). Without jQuery, any jQuery-dependent code fails.

  • Fix/Action: Load jQuery before any script that uses it. Recommended insertion in theme.liquid right after :

    Also verify the path is correct and the script isn’t deferred.

  • Additional notes: “x is not defined” can also stem from undeclared variables or scope issues. Other potential factors mentioned: conflicts with other libraries, incorrect file path, corrupted library file, or being offline while using a CDN.

  • Outcome: Multiple users confirmed that adding the jQuery CDN script resolved the error.

  • Status: Mostly resolved. An unanswered follow-up (in French) asks whether they must copy all the code from the linked URL; no direct reply yet.

  • Central artifacts: Code snippets (especially the jQuery tag) are key to understanding the fix.

Summarized with AI on December 12. AI used: gpt-5.

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

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.

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

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

Same Problem.

Did you get any solution?

Please let me know.

Hello , @designrepo

Please add this line of code :-

into your theme.liquid file after

5 Likes

Thank you.!

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)

This worked like a charm, thank you!

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

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

bonjour. il faut copier tout le code d votre lien ?