I have a Rails 6 application and assets are compiled using Webpack 4.39.1
(Webpacker gem) .
I have added JQuery 3.4.1
and Popper.js
to webpack ProvidePlugin
as follows (config/webpack/environment.js
):
const { environment } = require('@rails/webpacker');
const webpack = require('webpack');
environment.plugins.append('Provide', new webpack.ProvidePlugin({
$: 'jquery/src/jquery',
jQuery: 'jquery/src/jquery',
Popper: ['popper.js', 'default']
}));
module.exports = environment;
I have a javascript/packs/application.js
file and it is the entry point for webpack.
I have added Bootstrap 4.1.1
and importing it to application.js
.
Now, I'm trying to setup a tooltip as follows:
import "bootstrap/dist/js/bootstrap";
$( document ).ready(function() {
$('[data-toggle="tooltip"]').tooltip({
container: 'body',
placement: 'auto'
});
});
I am getting Uncaught TypeError: $(...).tooltip is not a function
error in dev console.
I also checked $.fn
and found none of the Bootstrap JS methods are part of JQuery prototype.
Any help would be appreciated! Thanks