I needed a popover on my site, so I though I could simply add this line in my js file : $('[data-toggle="popover"]').popover();
But, instead, I faced this error : TypeError: $(...).popover is not a function.

This problem seems to be documented (https://www.drupal.org/project/radix/issues/3011148), but instead of using with the provided workaround, I'd like to understand a bit more about how things are done in Radix 8.x-4.x.
Since Webpack is the new big thing here, I think it would serve the community to document more the implemented concept.

1.
In the parent theme (radix), theres 2 node_module dependency in the libraries.yml
- node_modules/popper.js/dist/umd/popper.min.js: {}
- node_modules/bootstrap/dist/js/bootstrap.min.js: {}
but node_modules doesn't exist. Should we remove this lib?

2.
On child theme, laravel-mix seems to import a jquery version inside node_modules (in the generated theme.script.js).
__webpack_require__(/*! jquery */ "./node_modules/jquery/dist/jquery.js")
I may be wrong, but doesn't it makes the website load 2 different jquery libraries?
If yes, maybe it's the reason why popover can't be found. Potentially a jQuery version conflict ?
Could we specify laravel-mix to use the Drupal's version?

Comments

JFKiwad created an issue. See original summary.

johanf’s picture

Hello

1) node_modules is coming after the 'npm install' . See step 2 in the README

2) wher is jQuery loaded 2 times ? in my radix subtheme libraries.yml i only have SUBTHEME_NAME.script.js

semiaddict’s picture

Category: Support request » Bug report
Status: Active » Needs review
StatusFileSize
new1.93 KB

Hi,
I just experienced the same issue in radix 8.x-4.5.
This is a conflict between Drupal's jQuery and the jQuery imported in webpack by bootstrap.
To solve it, I forced webpack to use the global jQuery (the one loaded by Drupal).

To do that, change the following in the theme's webpack.mix.js;

mix
  .setPublicPath('assets')
  .disableNotifications()
  .options({
    processCssUrls: false
  });

to:

mix
  .webpackConfig({
    externals: {
      jquery: 'jQuery'
    }
  })
  .setPublicPath('assets')
  .disableNotifications()
  .options({
    processCssUrls: false
  });

Attached is a patch against the latest release.

thursday_bw’s picture

StatusFileSize
new997 bytes

That patch in number 4 didn't apply for me using composer. I have re-rolled it.

It took me a long time to find this issue needing to debug quite a bit to figure out what the issue actually was.

In my case I was simply adding
```
(function ($, Drupal) {

'use strict';

Drupal.behaviors.carouselSlideEvent = {
attach: function (context) {
$('#carouselExample').on('slide.bs.carousel', function (e) {
console.log('Hello carousel');
}
};

})(jQuery, Drupal);
```

and the event was never being caught.

tstermitz’s picture

I was having problems adding a carousel. Maybe it was my code.

I did succeed by (fixing my code and) manually editing the theme.js file in my sub-theme using the suggestion #8 of this issue: https://www.drupal.org/project/radix/issues/3011148#comment-13028418

Note that the version of Bootstrap for me would be 4.1.3. I think 4.3.1 is incorrect.
'https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js': { type: external }

Double checking... Instead, I tried the suggestion here in #4 (editing my subtheme). And I can confirm that my carousel code is still working.

chrissnyder’s picture

Patch #4 worked for me. It is required to allow the Bootstrap External Link Pop-up module to work.

jwilson3’s picture

I've provided a patch for the default subtheme kit and a workaround for current sites with radix sub-themes that solves this on #2877496: Bootstrap js doesn't load in subtheme, feedback appreciated.

devkinetic’s picture

Status: Needs review » Reviewed & tested by the community

Using #5 worked for me. Jwilson3's patch does not work as expected. This needs to be commited!

elgandoz’s picture

After trying the method described above, I couldn't notice any difference.
I suggested a patch based on the @jwilson3 approach. The patch applies fine, but it doesn't modify you current or the base radix theme , it applies only on a new starterkit created by drush.
You will need to apply the same changes on your current theme manually.
Please check the and review: https://www.drupal.org/project/radix/issues/2877496
Tested with several Bootstrap snippet from the official documentation (Accordions, Tooltips, Modals).

idiaz.roncero’s picture

#4 works for me.

it is important to note that after adding the lines to webpack.mix.js it is needed to:

- Restart the "npm watch", if present.
- Clear caches.

For me, #4 is the correct solution to this particular problem, the other solution (manually inserting the libraries) work but by circumventing Webpack and its bundling capabilites.

devkinetic’s picture

@idiaz.roncero while #4 solved your issue, as it did mine as well, which patch cleanly applies to your starterkit? I found #5 to work when trying to include via composer. It would be great to confirm that.

idiaz.roncero’s picture

I did it manually - i tried the solution, not the patch - but i'll try it as soon as possible and let you know @devkinetic.

ljcarnieri’s picture

#4 works for me.

  • ckng committed 7f9c617 on 8.x-4.x authored by Thursday_BW
    Issue #3067615 by Thursday_BW, semiaddict: Use the jQuery shipped with...
devkinetic’s picture

YES! so happy about this little bugger!

doxigo credited ckng.

doxigo’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.