Why bootstrap is loaded from node module and not from libraries.yml like Barrio? (bug with the navbar)

Created on 28 November 2022, almost 2 years ago
Updated 5 April 2024, 6 months ago

Problem/Motivation

If I use the bootstrap 5 navbar with submenus, I get this error in the console :

bootstrap.min.js?v=9.4.8:6 Uncaught TypeError: i.createPopper is not a function
    at Mt._createPopper (bootstrap.min.js?v=9.4.8:6:23976)
    at Mt.show (bootstrap.min.js?v=9.4.8:6:22285)
    at Mt.toggle (bootstrap.min.js?v=9.4.8:6:22113)
    at HTMLAnchorElement.<anonymous> (bootstrap.min.js?v=9.4.8:6:26753)
    at HTMLDocument.s (bootstrap.min.js?v=9.4.8:6:4490)

This is because, in ibraries.yml, bootstrap js is loaded from :
js/bootstrap.min.js

But it should be the bundle :
bootstrap.bundle.min.js

If I modify the libraries.yml like this, it works :

global-styling:
  version: VERSION
  js: 
    //cdn.jsdelivr.net/npm/bootstrap@5.2.0/dist/js/bootstrap.bundle.min.js: { type: external, minified: true }
    js/barrio.js: {}
    js/custom.js: {}

Is this normal and intentional or is it a bug?

In barrio, bootstrap is not loaded in the libraries.yml file but from the theme configuration (we have the choice between cdn, local, etc). But in saas starter kit, it is generated from node modules.

I confess that I do not understand why it works like this. Can someone enlighten me?

๐Ÿ’ฌ Support request
Status

Closed: cannot reproduce

Version

5.0

Component

Code

Created by

๐Ÿ‡ซ๐Ÿ‡ทFrance sรฉbastien-fr Nantes - France

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • I was getting this same error with the navbar and they weren't opening or closing. After much head scratching found out that the popper.js file had not been included in the libraries.yml file when I created my subtheme. The bootstrap.bundle.min.js, I'm guessing includes popper.

    So for anyone that is also having issues check that you have the below file structure in libraries.yml and are not missing the popper.min.js file:

    global-styling:
    version: VERSION
    js:
    js/popper.min.js: { weight: -49 }
    js/bootstrap.min.js: { weight: -48 }
    js/barrio.js: {}
    js/custom.js: {}

  • ๐Ÿ‡ณ๐Ÿ‡ตNepal sandeshyadav Dhangadhi, Kailali

    If you landed to this page due to issues with dropdowns in the navbar, here is the cause of the problem and possible solutions.

    What is the causing the issue?

    For the dropdown to work, bootstrap uses a third party library popperjs. In the THEME.libraries.yml file of `SASS Starter Kit`, this library is missing which is causing the issue.

    To fix it,


    Use bootstrap.bundle.min.js instead of bootstrap.min.js . The bootstrap.bundle.min.js file includes popperjs library and thus solves the issue. You can use a CDN link(//cdn.jsdelivr.net/npm/bootstrap@5.2.0/dist/js/bootstrap.bundle.min.js) in your THEME.libraries.yml file.


    As mentioned by @GazzaT in #3 ๐Ÿ’ฌ Why bootstrap is loaded from node module and not from libraries.yml like Barrio? (bug with the navbar) Needs review , adding js/popper.min.js: { weight: -49 } to the THEME.libraries.yml solves the issue.

    Make sure to keep the weight -49 or lesser because popper.min.js needs to loaded before bootstrap.min.js. From the bootstrap docs,

    If you decide to go with the separate scripts solution, Popper must come first (if you're using tooltips or popovers), and then our JavaScript plugins

    .

    I would prefer because it is a modular approach and lets us exclude it(popperjs) if not required.

  • Status changed to Needs review over 1 year ago
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia ravi kant Jaipur

    #3 solution is working for me. Creating patch for this solution.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States TommyK

    Thank you for posting this. Adding text strings for toolbar and admin_toolbar to help others find it. I spent many hours debugging before actually figuring out a related issue.

  • Status changed to Closed: cannot reproduce 6 months ago
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia ravi kant Jaipur

    The solution according to the patch has already been applied on Branch 5.x latest release.

Production build 0.71.5 2024