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

lme*_*vil 4 reactjs bootstrap-4 reactstrap

我是新手.我正在尝试使用bootsrap 4创建一个react应用程序.我正在使用reactstrap,接下来的步骤:

create-react-app my-app

npm install bootstrap --save

npm install --save reactstrap@next react react-dom
Run Code Online (Sandbox Code Playgroud)

在src/index.js文件中导入Bootstrap CSS:import'bootstrap/dist/css/bootstrap.min.css';

但是,当我启动我的应用程序时,我收到此错误:

编译失败.

./src/index.js找不到模块:无法解析'D:\ React\my-app2\src'中的'bootstrap/dist/css/bootstrap.css'

我曾经在CDN中使用bootstrap,你知道,在我的html页面中, 链接rel ="stylesheet"...等和脚本src =""......等.但是使用reactstrap,js文件在哪里?(jquery,popper,bootstrap)(当我运行npm install bootstrap时,它们都在一起--save?)

谢谢

0le*_*leg 5

从错误中可以看出,它试图在src文件夹中查找bootstrap/dist/css/bootstrap.css.但是,如果查看项目文件,您会注意到bootstrap文件夹位于node_modules文件夹内的1级(在根目录中).

因此,要么搜索并更正您的路径:

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

或者添加(如果你还没有这样做)对index.js的引用:

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


这是文件树:

+-node_modules
 |-bootstrap
  |-dist
   |-css
    |-bootstrap.css
+-src
 |-index.js
Run Code Online (Sandbox Code Playgroud)