Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap in React -- can't resolve jQuery Module?

I'm working on a project using React. I've tried to install Bootstrap, but my project won't compile. I've installed [email protected] using npm. But I keep on getting the following error message:

./node_modules/bootstrap/dist/js/bootstrap.js
Module not found: Can't resolve 'jquery' in '/Users/my_name/React_Projects/my_react_project/node_modules/bootstrap/dist/js'

This is a project that I was given to work on, so I haven't made it from scratch -- so I'm just piecing things together as I go. I thought it may be an error with Webpack, so one of the things I tried to do was add jquery as an external resource in my webpack.config.js file -- but there is no such file in the project at this point.

This project was created using react-scripts, which I am told is a wrapper around Webpack. Anyone have any idea how to resolve this issue? How can I get jQuery to work so I can start using Bootstrap?

like image 574
Leia_Organa Avatar asked Mar 31 '18 15:03

Leia_Organa


People also ask

Does React-Bootstrap use jQuery?

React is a simple library that creates interactive front end web pages, with a component-based architecture that can be nested or put side by side. Hence, adding third party libraries to React is easy. However, Bootstrap relies heavily on jQuery for powering its user interface components.

Can we use jQuery in React?

Yes, we can use jQuery in ReactJs.

Can we use Bootstrap CDN in React?

The Bootstrap CDN is the easiest way to add Bootstrap to your React app. No extra installation or download is required. You'll only have to include a link to the CDN in the head section of your application entry file. In a typical React application created with create-react-app , that would be in the public/index.


2 Answers

You will need to install the jquery and popper.js packages from npm. In your terminal, run below command:

npm install jquery popper.js

or

yarn add jquery popper.js

Next, go to the src/index.js file and add the following imports:

import $ from 'jquery';
import Popper from 'popper.js';
import 'bootstrap/dist/js/bootstrap.bundle.min';

There you have it. You can now use the full power of Bootstrap and jQuery in your React application.

like image 131
Voke Junior Avatar answered Oct 11 '22 10:10

Voke Junior


This post solved my issues, maybe it can help you guys out too. Just run these two commands.

npm install --save resolve-url-loader --only=dev
npm i --save-dev bootstrap@next bootstrap-loader tether jquery

Look here link

like image 33
Zablon Dawit Avatar answered Oct 11 '22 11:10

Zablon Dawit