找不到模块:无法解析“C:\Users\test\counter-app\src”中的“bootstrap/dist/css/bootstrap.css”

Mut*_*n K 4 reactjs react-bootstrap react-component

我是反应 js 的新手。我正在尝试创建一个组件。为此,我已经安装了成功安装的引导程序(版本 4.1.1)。

然后我在 index.js 中导入了相同的内容,并在重新加载页面 (localhost:3000) 时收到错误消息:

Module not found: 
Can't resolve 'bootstrap/dist/css/bootstrap.css' in 'C:\Users\test\counter-app\src'
Run Code Online (Sandbox Code Playgroud)

我的index.js

import React from "react";
import ReactDOM from "react-dom";
import "./index.css";
import App from "./App";
import * as serviceWorker from "./serviceWorker";
import "bootstrap/dist/css/bootstrap.css";

ReactDOM.render(<App />, document.getElementById("root"));

serviceWorker.unregister();
Run Code Online (Sandbox Code Playgroud)

我的package.json

{
  "name": "counter-app",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "react": "^16.8.4",
    "react-dom": "^16.8.4",
    "react-scripts": "2.1.8"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": [
    ">0.2%",
    "not dead",
    "not ie <= 11",
    "not op_mini all"
  ]
}
Run Code Online (Sandbox Code Playgroud)

请帮我解决这个问题。

Jam*_*ney 5

像这样将导入路径更改为 bootstrap.min.css:

导入 'bootstrap/dist/css/bootstrap.min.css';