Drupal 8 Tip: Debugging JavaScript error "Uncaught ReferenceError: Drupal is not defined"

Megan's picture

She has: 11,421 posts

Joined: Jun 1999

Is your jQuery not working when logged out in Drupal 8? Are you getting a console error "Uncaught ReferenceError: Drupal is not defined"? In order to use jQuery behaviours in Drupal 8 you need to include core/drupal as well as core/jquery in your libraries file. Like this:

  dependencies:
    - core/drupal
    - core/jquery

See here for a little more explanation of JavaScript behaviours in Drupal 8: http://sqndr.github.io/d8-theming-guide/javascript/behaviors.html

They have: 66 posts

Joined: Jan 2016

Thanks for the tip. Now I know why I have those errors in my Drupal application.

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.