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?
| Comment | File | Size | Author |
|---|---|---|---|
| #5 | use-global-jquery-3067615-5.patch | 997 bytes | thursday_bw |
| #4 | use-global-jquery-3067615-4.patch | 1.93 KB | semiaddict |
Comments
Comment #2
johanf commentedHello
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
Comment #3
elgandoz commentedI think this issues are relevant:
I'm investigating as well how can we fix this properly using laravel mix webpack configuration
Comment #4
semiaddict commentedHi,
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;
to:
Attached is a patch against the latest release.
Comment #5
thursday_bw commentedThat 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.
Comment #6
tstermitzI 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.
Comment #7
chrissnyderPatch #4 worked for me. It is required to allow the Bootstrap External Link Pop-up module to work.
Comment #8
jwilson3I'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.
Comment #9
devkinetic commentedUsing #5 worked for me. Jwilson3's patch does not work as expected. This needs to be commited!
Comment #10
elgandoz commentedAfter 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).
Comment #11
idiaz.roncero#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.
Comment #12
devkinetic commented@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.
Comment #13
idiaz.ronceroI did it manually - i tried the solution, not the patch - but i'll try it as soon as possible and let you know @devkinetic.
Comment #14
ljcarnieri commented#4 works for me.
Comment #16
devkinetic commentedYES! so happy about this little bugger!
Comment #18
doxigo commented