I'm just finish install bootstrap 5 version ^5.0.0-alpha1
and import bootstrap in app.js
import "bootstrap"
other.js
var myModal = new bootstrap.Modal(document.getElementById('myModal'));
myModal.show();
when I run the code it give me error ReferenceError: bootstrap is not defined.
then I try to import bootstrap in other.js like this
import bootstrap from "bootstrap"
but when I run npm run dev
error "export 'default' (imported as 'bootstrap') was not found in 'bootstrap'
If Im import modal manually like import { Modal } from "bootstrap"
it give me error "TypeError: Illegal invocation"
Bootstrap 5 is designed to be used without jQuery, but it's still possible to use our components with jQuery. If Bootstrap detects jQuery in the window object it'll add all of our components in jQuery's plugin system; this means you'll be able to do $('[data-bs-toggle="tooltip"]').
Many of our components require the use of JavaScript to function. Specifically, they require our own JavaScript plugins and Popper.
Many of our components require the use of JavaScript to function. Specifically, they require jQuery, Popper. js, and our own JavaScript plugins.
Bootstrap uses jQuery for JavaScript plugins (like modals, tooltips, etc). However, if you just use the CSS part of Bootstrap, you don't need jQuery.
If anyone trying to use with webpack, this solution worked for me.
window.bootstrap = require('bootstrap/dist/js/bootstrap.bundle.js');
If you use:
import { Modal } from 'bootstrap'
then the syntax to use will be:
let myModal = new Modal(document.getElementById('myModal'));
myModal.show();
Working for me on a relatively simple setup with Vite and bootstrap-5.0.0-beta1.
Bootstrap 5.1 + webpack 5:
app.js
import * as bootstrap from 'bootstrap';
window.bootstrap = bootstrap;
or if you only need Modal:
import * as bootstrap from 'bootstrap';
window.Modal = bootstrap.Modal;
and then you could use in other.js
like:
var myModal = new Modal(document.getElementById('myModal'));
myModal.show();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With