Skip to content
Advertisement

Bootstrap JS not working with Rails Importmap

I have a Rails 7 App that I’m using Importmap with. I’m loading the Bootstrap JS via the gem and docs so my config/importmap.rb has:

JavaScript

config/initializers/assets.rb

JavaScript

application.js

JavaScript

Stuff like dropdowns activated via data attributes work well but my custom JS gives the error: Uncaught TypeError: bootstrap.Popover is not a constructor

Advertisement

Answer

How to initialize Popper (tooltips) with importmaps

You’re very close. I changed your import statement for bootstrap in application.js, and modified the pin statements in importmaps to align with the documentation (linked below). Everything is working.

app/javascripts/application.js

JavaScript

Note, the inner code is from Bootstrap’s docs and will initialize all the tooltips on the screen.

config/importmap.rb

JavaScript

The last two lines are slightly different than what you had, but are copy-pasted from the gem’s docs.

As you did, I also had to add the following:

config/initializers/assets.rb

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement