0

I know that this question has been asked previously many times but any of the solutions are not working in my case so please, I request if anyone can help me with this situation please provide me assistance. I have added dependency of the core jQuery(along with other core libraries) in my theme.libraries.yml but only core jQuery is not loading in my drupal frontend and the console is showing the error of jQuery is not defined. Also other drupal core libraries as working fine only jQuery is not loading.

My code of various files is as follows

theme.libraries.yml

global-styling:   
  version: 1.x   
  css:
    theme:
      css/bootstrap.css: {}
      css/custom.css: {}
      css/owl.carousel.min.css: {}
      css/owl.theme.default.min.css: {}
      css/responsive.css: {}
      css/style.css: {}
      fonts/fonts.css: {}   
  js:
    js/bootstrap.js: {}
    js/owl.carousel.min.js: {}
    js/popper.js: {}
    js/scripts.js: {}   
  dependencies:
    - core/jquery
    - core/jquery.once
    - core/drupal

theme.info.yml

name: wcsb
type: theme
description: 'Another outstanding WebCube Theme'
package: Core
version: '0.1.2'
core: '8.x'
base theme: classy

libraries:
  - wcsb/global-styling

regions:
  header_bar_1: 'Header Bar 1'
  header_bar_2: 'Header Bar 2'
  header_bar_3: 'Header Bar 3'
  header_bar_4: 'Header Bar 4'
  mobile_header_1: 'Mobile Header 1'
  mobile_header_2: 'Mobile Header 2'
  slider_images: 'Slider Images'
  breadcrumb: Breadcrumb
  featured_top: 'Featured top'
  above_content: 'Above Content'
  content: Content
  below_content: 'Below Content'
  sidebar_first: 'Sidebar first'
  sidebar_second: 'Sidebar second'
  featured_bottom_first: 'Featured bottom first'
  featured_bottom_second: 'Featured bottom second'
  featured_bottom_third: 'Featured bottom third'
  footer_first: 'Footer first'
  footer_second: 'Footer second'
  footer_third: 'Footer third'
  footer_fourth: 'Footer fourth'
  footer_fifth: 'Footer fifth'

list of scripts loading

<body class="path-frontpage page-node-type-page" data-new-gr-c-s-check-loaded="14.1002.0" data-gr-ext-installed=""
cz-shortcut-listen="true">

<script type="application/json" data-drupal-selector="drupal-settings-json">
    {
        "path": {
            "baseUrl": "\/",
            "scriptPath": null,
            "pathPrefix": "",
            "currentPath": "node\/1",
            "currentPathIsAdmin": false,
            "isFront": true,
            "currentLanguage": "en"
        },
        "pluralDelimiter": "\u0003",
        "suppressDeprecationErrors": true,
        "ajaxTrustedUrl": {
            "form_action_p_pvdeGsVG5zNF_XLGPTvYSKCf43t8qZYSwcfZl2uzM": true
        },
        "user": {
            "uid": 0,
            "permissionsHash": "508c848d9cf616f3b3735479b8cad945e128b7dbb0a534206170c7d3643afe05"
        }
    }
</script>
<script src="/core/assets/vendor/jquery-once/jquery.once.min.js?v=2.2.3"></script>
<script src="/core/misc/drupalSettingsLoader.js?v=8.9.13"></script>
<script src="/core/misc/drupal.js?v=8.9.13"></script>
<script src="/core/misc/drupal.init.js?v=8.9.13"></script>
<script src="/themes/custom/wcsb/js/bootstrap.js?v=8.9.13"></script>
<script src="/themes/custom/wcsb/js/owl.carousel.min.js?v=8.9.13"></script>
<script src="/themes/custom/wcsb/js/popper.js?v=8.9.13"></script>
<script src="/themes/custom/wcsb/js/scripts.js?v=8.9.13"></script>
<script src="/modules/contrib/commerce/modules/cart/js/commerce_cart.js?v=8.9.13"></script>

console errors console showing jquery is not defined errors.

8
  • Can you try with the version: 1.x removed?
    – leymannx
    Mar 31, 2021 at 12:48
  • @leymannx I removed version: 1.x but nothing changed, issue is still there Mar 31, 2021 at 13:59
  • You flushed caches at least twice of course?
    – leymannx
    Mar 31, 2021 at 14:01
  • @leymannx yes I have cleared cache about dozen of times but noting happend Mar 31, 2021 at 14:27
  • Did you check if the file actually exists in core/assets/vendor/jquery-once/jquery.once.min.js in the location just to be sure. And Also disable css and js aggregation. Apr 1, 2021 at 3:01

1 Answer 1

1

Solved The problem was in my .theme file where it was unsetting the core jQuery library. The problem code:

function theme_js_alter(&$javascript, \Drupal\Core\Asset\AttachedAssetsInterface $assets)
{
    unset($javascript['core/assets/vendor/jquery/jquery.min.js']);
}

Thanks to @AlfredArmstrong for providing the suggestion of reviewing the php files

Your Answer

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

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