问题
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:
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
来源:https://stackoverflow.com/questions/49538124/reactstrap-create-react-app-not-found-bootstrap-dist-css-bootstrap-css-v-4