Blogs

Blogs

From our minds to yours

How to Crack jQuery Error: JQuery is not defined?

jquery

How often we come across an error like 'jQuery is not defind' in Drupal 8? One too many times! In most cases, this error can be resolved by passing drupal setting argument in drupal js behaviour. In your theme.libraries.yml file of your theme that you have used add these line in your global scripting tag 

Dependencies:

  • core/jquery
  • core/drupal
  • core/drupalSettings 

Once you are done with Step 1 then clear the cache.

Open your Drupal JS behaviour (where you have written your JS code) file and define these arguments in your drupal js behaviour file.

Example:

 (function($, Drupal, drupalSettings) {

  Drupal.behaviors.behaviorname = 

           ---  code ----

  };

 })(jQuery , Drupal, drupalSettings);

We hope this works well for resolving the error.

LEAVE A COMMENT

Fields marked with an * are mandatory.