0

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.

Noman Ali
  • 2,497
  • 3
  • 32
  • 63

3 Answers3

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.

Rishi Raj
  • 404
  • 3
  • 11
1

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>
Hans Yulian
  • 954
  • 6
  • 21
0

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 bootstrap@3.3.7 and jquery@2.2.4.

Ref - issue

Nithin Kumar Biliya
  • 1,895
  • 1
  • 25
  • 47