reactstrap - create-react-app - not found bootstrap/dist/css/bootstrap.css - v.4

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-24 07:30:12

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!