简体   繁体   中英

Bootstrap's JavaScript requires jQuery - Reactjs

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.

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

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>

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM