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.

4
  • 2
    I think you would need to add jquery to your html file Commented Sep 26, 2017 at 6:16
  • Adding to html file file, removed the error for now. Thanks :) Commented Sep 26, 2017 at 6:20
  • Glad I could help :) Commented Sep 26, 2017 at 6:21
  • Maybe a duplicate: stackoverflow.com/questions/28969861/… Commented Sep 26, 2017 at 6:38

3 Answers 3

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>
Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.