Tooltip not working even though JQuery and Bootstrap are installed
It looks like similar questions exist here and here , but the answers provided do not address my situation.
I have a Node / Express / Webpack stack on my server where I used npm to install Bootstrap 4 alpha 6 along with tether.js, the required dependency for the tooltip functionality. In my main JS file, as defined in webpack config, I imported the binding using and initialized the Bootstrap tooltip function using the following snippets:
import "tether";
and
$(function () {
$('[data-toggle="tooltip"]').tooltip()
})
Then in my index.hbs (I am using descriptors to display my pages), I have the following snippet that implements the tooltip:
<button type="button" class="btn btn-secondary" data-toggle="tooltip" title="Tooltip on top">
Tooltip on top
</button>
The scripts compile successfully without any errors or warnings. However, when loading the page in the browser, I get an error tooltip is not a function...
. It shouldn't be, right? I can confirm that JQuery is working fine as the following snippet under one init hint as shown above is rendering without any hiccups:
$('p#some').html('from jquery');
As you can see below, in my webpack.config.js file, both JQuery and Tether plugins were running, as well as one for Tooltip:
plugins: [
new webpack.optimize.UglifyJsPlugin({ mangle: false, sourcemap: false }),
new ExtractTextPlugin({ filename: "../../public/dist/main.min.css" }),
new webpack.ProvidePlugin({
$: "jquery",
jQuery: "jquery",
"window.jQuery": "jquery",
Tether: "tether",
"window.Tether": "tether",
Alert: "exports-loader?Alert!bootstrap/js/dist/alert",
Button: "exports-loader?Button!bootstrap/js/dist/button",
Carousel: "exports-loader?Carousel!bootstrap/js/dist/carousel",
Collapse: "exports-loader?Collapse!bootstrap/js/dist/collapse",
Dropdown: "exports-loader?Dropdown!bootstrap/js/dist/dropdown",
Modal: "exports-loader?Modal!bootstrap/js/dist/modal",
Popover: "exports-loader?Popover!bootstrap/js/dist/popover",
Scrollspy: "exports-loader?Scrollspy!bootstrap/js/dist/scrollspy",
Tab: "exports-loader?Tab!bootstrap/js/dist/tab",
Tooltip: "exports-loader?Tooltip!bootstrap/js/dist/tooltip",
Util: "exports-loader?Util!bootstrap/js/dist/util",
}),
new webpack.LoaderOptionsPlugin({ postcss: [autoprefixer] }),
]
The project files are available as an internal repo here if that helps.
source to share
Couple of problems as I faced similar problems myself.
1) You need to provide a link to popper.js in the plugins section in your webpack.config.js file;
Popper: ['popper.js', 'default'],
2) in the main js, import the required plugin;
import 'bootstrap/js/dist/tooltip';
More info here: Bootstrap 4 - Installing Webpack
source to share