How do I fix an uncaught TypeError? 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




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

How can I fix this?
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 &gt; script[type="application/json"][data-drupal-selector="drupal-settings-json"], body &gt; script[type="application/json"][data-drupal-selector="drupal-settings-json"]');

  ....


This code explained that the drupalSettings is contained in 

&lt;script type="application/json" data-drupal-selector="drupal-settings-json"&gt;


And it must be under &lt;head&gt; or &lt;body&gt;.

I suspect that your &lt;script&gt; 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.