When logged in as a user (not admin), some JS scripts do not load on certain pages.

I found out about this issue because I am using the module EU Cookie Compliance and the scripts it uses (eu_cookie_compliance.js, jquery.cookie.shim.js, js.cookie.min.js) aren't always loaded.

I am using a JS method provided by the EU Cookie Compliance module in my custom theme and found out it triggered an error on some pages (because the scripts aren't loaded).

For example, the scripts load on /user/2 but don't on /user/2/orders or /user/2/customer as you can see on the below image. Why does this happen?

enter image description here

I can see no option in EU Cookie Compliance module that prevents loading the script on some pages. Nor did I find anything in the code.


I have now included eu_cookie_compliance as a dependency in my theme:

  - core/drupal
  - core/jquery
  - core/jquery.once
  - core/drupalSettings
  - eu_cookie_compliance/eu_cookie_compliance
  - eu_cookie_compliance/eu_cookie_compliance_bare

And this fixed the fact that the scripts weren't loaded on all pages. That said, I now have errors on these specific pages.

All I do in my theme's JS (radix_sub.script.js) is using Drupal.eu_cookie_compliance.hasAgreed() which now triggers the following errors:

enter image description here

I have tried declaring only eu_cookie_compliance and only eu_cookie_compliance_bare and both in my theme libraries, and the errors are identical.

  • 1
    Yeah, it's not loading on some pages because 1. It's not required for those pages. Or 2. There's a bug in the module somewhere. I'm guessing it's #1. (p.s. sorry, deleted earlier comment to post as answer.)
    – sonfd
    Sep 10, 2020 at 12:41

1 Answer 1


I don't know why it's not loading on some pages, but ultimately it's because the library isn't required for those pages. If a module's library is required by your theme then you need to declare it as a dependency.

You can do this for your library in your theme's libraries.yml file. See the Declaring dependencies documentation.

# my_theme.libraries.yml
# It's not clear if you want the bare or full cookie compliance library
    js/my_libary.js: {}
    - eu_cookie_compliance/eu_cookie_compliance
    - eu_cookie_compliance/eu_cookie_compliance_bare
  • Ok, that's weird. You are right, declaring these as dependencies in my theme fixes the fact that the EU Cookie Compliance module scripts aren't loaded on all pages. But it now triggers other errors on those specific pages, and the style that I applied to the cookie compliance banner provided by the module aren't applied anymore.
    – MrUpsidown
    Sep 10, 2020 at 12:47
  • Don't include both libraries as dependencies. I wasn't sure which one you wanted so I showed both. It sounds like you probably want the bare library
    – sonfd
    Sep 10, 2020 at 12:53
  • Please see the edit in my question. I have tried with both dependencies, or only eu_cookie_compliance or only eu_cookie_compliance_bare and the errors are identical.
    – MrUpsidown
    Sep 10, 2020 at 13:01
  • Out of ideas, I also tried switching to the DEV version of the module and the problem is the same (not loading on the pages I mentioned).
    – MrUpsidown
    Sep 10, 2020 at 13:42
  • You need to debug the console error message you get when the library is included on those extra pages.
    – sonfd
    Sep 10, 2020 at 13:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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