2

I am using Drupal 8.1.8. It is giving me many JavaScript errors.

Uncaught TypeError: Cannot read property 'permissionsHash' of undefined
Uncaught TypeError: Cannot set property 'StateModel' of undefined
Uncaught TypeError: Cannot set property 'AuralView' of undefined
Uncaught TypeError: Cannot set property 'KeyboardView' of undefined
Uncaught TypeError: Cannot set property 'RegionView' of undefined
Uncaught TypeError: Cannot set property 'VisualView' of undefined
Uncaught TypeError: Cannot read property 'uid' of undefined
Uncaught TypeError: Cannot read property 'currentPath' of undefined
Uncaught TypeError: Cannot read property 'currentPathIsAdmin' of undefined
Uncaught TypeError: Cannot read property 'url' of undefined
Uncaught TypeError: Cannot read property 'currentQuery' of undefined

Core Javascript Errors

There is no error in my local copy, but it happen when I uploaded in live hosting.

How can I fix this?

8
  • 3
    um... lack of information. And should we consider DA a debug service provider?
    – Jimmy Ko
    Commented Aug 9, 2016 at 15:47
  • What more information I need to provide ? Commented Aug 10, 2016 at 12:03
  • Can you try to type drupalSettings in browser console to see what's the data contained in the object?
    – Jimmy Ko
    Commented Aug 10, 2016 at 16:23
  • Just dump one, here is the output: Object {} proto:Object defineGetter:__defineGetter__() defineSetter:__defineSetter__() lookupGetter:__lookupGetter__() lookupSetter:__lookupSetter__() constructor:Object() hasOwnProperty:hasOwnProperty() isPrototypeOf:isPrototypeOf() propertyIsEnumerable:propertyIsEnumerable() toLocaleString:toLocaleString() toString:toString() valueOf:valueOf() get proto:__proto__() set proto:__proto__() Commented Aug 11, 2016 at 10:53
  • I can't see it, can you post in the question?
    – Jimmy Ko
    Commented Aug 11, 2016 at 10:53

1 Answer 1

13

All the properties can be searched and found from the code in Drupal core. And they seems to be the properties of drupalSettings object in JS.

This object is initialised in core/misc/drupalSettingsLoader.js.

(function () {

  'use strict';

  // Use direct child elements to harden against XSS exploits when CSP is on.
  var settingsElement = document.querySelector('head > script[type="application/json"][data-drupal-selector="drupal-settings-json"], body > script[type="application/json"][data-drupal-selector="drupal-settings-json"]');

  ....

This code explained that the drupalSettings is contained in

<script type="application/json" data-drupal-selector="drupal-settings-json">

And it must be under <head> or <body>.

I suspect that your <script> tag is wrapped in other element. Please check your template files and remove the wrappers or check if there is a content with missing closing tag.

19
  • I see the <script type="application/json" data-drupal-selector="drupal-settings-json"> tag is showing below the footer. I think this is added dynamically by Drupal. Commented Aug 11, 2016 at 11:30
  • I can find it is wrapped within <em> when I inspect the link you provide. It is not under <footer>.
    – Jimmy Ko
    Commented Aug 11, 2016 at 11:32
  • 2
    @Pierre.Vriens Because the keywords are easily to be searched and found within Drupal core. Maybe it is easy to me but not others. Let me rephrase that.
    – Jimmy Ko
    Commented Aug 11, 2016 at 13:07
  • 2
    Sometimes broad questions result in common errors. The common error is the footer JS tags were wrapped in an additional HTML tag. In one commenter's case, it was the <em> tag. In my case, it was a <div>. With the easy access to the theme layer via Twig, I am sure someone is going to run into the problem of "Don't wrap the Drupal footer JS tags in another HTML tag or all scripts will throw an error." This is a common problem identified by the OP's question. It is not broad at all.
    – Joe Hyde
    Commented Dec 26, 2016 at 5:28
  • 1
    In my case i was having like this <js-bottom-placeholder token="{{ placeholder_token }}"> </div> </body> </html>
    – Wasim Khan
    Commented May 16, 2019 at 6:23

Not the answer you're looking for? Browse other questions tagged or ask your own question.