skip to Main Content

I have to use bootstrap with reactjs and when i try to import Bootstrap.js it gives me error

Bootstrap’s JavaScript requires jQuery

Here is my import statements (I tried following)

import $ from 'jquery';
import jQuery from 'jquery'; //I installed jquery using npm
import '@shopify/polaris/jquery'; //I put jquery.js file 
import '@shopify/polaris/bootstrap';

Nothing is seems to work here.

3

Answers


  1. You can use React Bootstrap as well as an alternative. It has all elements of the Bootstrap plus it blends well with ReactJS elements.

    Login or Signup to reply.
  2. in your HTML file:

    <html>
          <head>
    
               ..................
               ..................
               ..................
          </head>
    
          <body>
               ..................
               <script src="jquery.js"></script> // <<<<<< you missing import jquery here
               <script src="bootstrap.js"></script> // <<<<<<< you have this one
               ..................
          </body>
    </html>
    
    Login or Signup to reply.
  3. Bootstrap requires jquery to be available on the global object. Try the below –

    import 'bootstrap/dist/css/bootstrap.min.css';
    
    const $ = require('jquery');
    window.$ = $;
    window.jQuery = $;
    require('bootstrap/dist/js/bootstrap.min');
    

    I have verified it for [email protected] and [email protected].

    Ref – issue

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search