5

I am new in this. I am trying to create a react app with bootsrap 4. I am using reactstrap following the next steps:

create-react-app my-app

npm install bootstrap --save

npm install --save reactstrap@next react react-dom

Import Bootstrap CSS in the src/index.js file: import 'bootstrap/dist/css/bootstrap.min.css';

But when I start my app, I am getting this error:

Failed to compile.

./src/index.js Module not found: Can't resolve 'bootstrap/dist/css/bootstrap.css' in 'D:\React\my-app2\src'

I used to use bootstrap with CDN, you know, in my html page, link rel="stylesheet" ... etc and script src=""... etc. But using reactstrap, where are the js files? (jquery, popper, bootstrap) (are all together when I run npm install bootstrap --save ?)

Thanks

1
  • 1
    Go take a look inside the ./node_modules/bootstrap folder and you'll be able to see where is located your css file. Commented Mar 28, 2018 at 15:13

1 Answer 1

8

As you see from the error, it tries to look for bootstrap/dist/css/bootstrap.css inside your src folder. But if you look at your project files, you will notice that the bootstrap folder is located 1 level up (in the root) inside node_modules folder.

So either search and correct your path to:

../node_modules/bootstrap/dist/css/bootstrap.css.

Or add (if you still haven't done this) a reference to your index.js:

import '../node_modules/bootstrap/dist/css/bootstrap.css'.


This is the files tree:

+-node_modules
 |-bootstrap
  |-dist
   |-css
    |-bootstrap.css
+-src
 |-index.js
Sign up to request clarification or add additional context in comments.

2 Comments

just simply amazing , and I am wondering why all the tutorials have such a path import 'bootstrap/dist/css/bootstrap.min.css'; ? any thoughts on that?
The file structure might depend on the tutorial. The best way is to know where the CSS file is located, what is the pass to it and use it.

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.