I have an angular application where I use the Bootstrap 5.3 Javascript module, correctly installed with npm i bootstrap
and npm i @types/bootstrap
(JQuery and Popper.js were automatically installed as well).
While developing and using the application with ng serve
, I am able to import and use the bootstrap modules in my typescript files with no problems or conflicts (creating instances, passing options, accessing methods...).
The problem is that as soon as i build the project (just ng build
with no options) the Carousel and Collapse animations start to glitch, animating for example only one of the items of the Carousel or only the "show" and not the "hide" of the Collapse.
Additional information:
Bootstrap even works in the markup, although I never linked bootstrap anywhere with a <script>
tag.
About that, I observed that bootstrap "activates" globally when i first import * as bootstrap
in the code, but I don't really have evidences to support that theory.
Both the Carousel and the Collapse I am referring to, are used in the markup via the data-bs-*
attributes.
If I do link the bootstrap 5.3 Javascript in the <head>
, leaving the imports in the typescript files as they are, the Carousel behaviour just go back to normal, while the Collapse glitches in another way (clicking on the button just perform the "show" part and never the "hide").
Does anyone have an idea about why there is such a difference between the serve and the build? Should I instantiate bootstrap components either in the code or in the markup without mixing?