关于reactjs:reactstrap – create-react-app – not found bootstrap / dist / css / bootstrap.css – v.4

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

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

1
2
3
4
5
create-react-app my-app

npm install bootstrap --save

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

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

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

Failed to compile.

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

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

谢谢


从错误中可以看出,它试图在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'

这是文件树:

1
2
3
4
5
6
7
+-node_modules
 |-bootstrap
  |-dist
   |-css
    |-bootstrap.css
+-src
 |-index.js