Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

252
Visualizações
Dynamic modals using Bootstrap 5.0.0 and Webpacker

Since Bootstrap 5.0.0, it seems Bootstrap JS file must be loaded at the end of the <body> in order to render dynamically loaded Modals (and maybe other features). Check this issue on GitHub

Agree with this issue. This happens in bootstrap 5.x production release irrespective of how you initialize the modal. Either dynamically via JS or via Data attributes.

Currently the workaround to overcome this issue is to load the bootstrap.bundle.js within the HTML body and not in the head. But it ideally cannot be the solution to this issue.

Do you know another workaround for this issue ?


Error:
// Error happens when I want to display a Modal using JS

var modal = new bootstrap.Modal(document.getElementById('my-modal');
modal.show();

// Uncaught TypeError: BACKDROP: Option "rootElement" provided type "null" but expected type "element".
//    typeCheckConfig bootstrap.bundle.js:190
//    typeCheckConfig bootstrap.bundle.js:184
//    _getConfig bootstrap.bundle.js:4603
//    Backdrop bootstrap.bundle.js:4539
//    _initializeBackDrop bootstrap.bundle.js:4864
//    Modal bootstrap.bundle.js:4721
//    <anonymous> debugger eval code:2


A solution:

Simplest workaround is to load our JS at the end of the <body> tag:

# app/views/layout/application.html.erb

<body>
  <%= yield %>
  <%# this `javascript_pack_tag` is initially inside the `<head>` tag
  <%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>
</body>
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda