reactstrap-创建反应应用程序-找不到bootstrap/dist/css/bootstrap.css-v.4 [英] reactstrap - create-react-app - not found bootstrap/dist/css/bootstrap.css - v.4
问题描述
我是新来的.我正在尝试使用bootsrap 4创建一个React应用.我正在按照以下步骤使用 reactstrap :
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
在src/index.js文件中导入Bootstrap CSS: 导入'bootstrap/dist/css/bootstrap.min.css';
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找不到模块:无法解析 'D:\ React \ my-app2 \ src'中的'bootstrap/dist/css/bootstrap.css'
./src/index.js Module not found: Can't resolve 'bootstrap/dist/css/bootstrap.css' in 'D:\React\my-app2\src'
我曾经在CDN上使用引导程序,在我的HTML页面中, 链接rel ="stylesheet" ...等以及脚本src =" ...等 .但是使用 reactstrap ,js文件在哪里? (jquery,popper,bootstrap)(当我运行 npm install bootstrap --save 吗?)时
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 ?)
谢谢
推荐答案
从错误中可以看出,它试图在中查找 bootstrap/dist/css/bootstrap.css src 文件夹.但是,如果查看项目文件,则会发现 bootstrap 文件夹位于 node_modules 文件夹内的第一层(在根目录中).
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
.
或添加(如果尚未执行此操作)对 index.js 的引用:
Or add (if you still haven't done this) a reference to your index.js:
import '../node_modules/bootstrap/dist/css/bootstrap.css'
.
这是文件树:
+-node_modules
|-bootstrap
|-dist
|-css
|-bootstrap.css
+-src
|-index.js
这篇关于reactstrap-创建反应应用程序-找不到bootstrap/dist/css/bootstrap.css-v.4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!