无法解析'../node_modules/bootstrap/dist/css/bootstrap.min.css'?

问题描述 投票:0回答:1

我试图在我的项目中使用react-bootstrap-table2来创建一个简单的引导程序表,但我收到错误:

编译失败:未找到模块:无法解析'/ Users / xxx / Documents / xxx / src / routes / home'中的'../node_modules/bootstrap/dist/css/bootstrap.min.css'。

我确实安装了所有必要的软件包并验证了bootstrap.min.css存在于应有的位置。

我的代码看起来像这样:

import React from 'react';
import '../node_modules/bootstrap/dist/css/bootstrap.min.css'; 
import BootstrapTable from 'react-bootstrap-table-next';

class Home extends React.Component {
  state = {
    products: [
      {
        id: 1,
        name: 'TV',
        'price': 1000
      },
      {
        id: 2,
        name: 'Mobile',
        'price': 500
      },
      {
        id: 3,
        name: 'Book',
        'price': 20
      },
    ],
    columns: [{
      dataField: 'id',
      text: 'Product ID'
    },
    {
      dataField: 'name',
      text: 'Product Name'
    }, {
      dataField: 'price',
      text: 'Product Price',
      sort: true
    }]
  } 

  render() {
    return (
      <div className="container" style={{ marginTop: 50 }}>
        <BootstrapTable 
        striped
        hover
        keyField='id' 
        data={ this.state.products } 
        columns={ this.state.columns } />
      </div>
    );
  }
}

export default Home;

我的package.json文件如下所示:

{
  "name": "codist.org",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "bootstrap": "^4.0.0",
    "material-ui": "^1.0.0-beta.25",
    "material-ui-icons": "^1.0.0-beta.17",
    "react": "^16.2.0",
    "react-bootstrap-table-next": "^1.1.3",
    "react-dom": "^16.2.0",
    "react-router-dom": "^4.2.2",
    "react-scripts": "^1.1.5",
    "reactstrap": "^6.3.0"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject"
  },
  "proxy": "http://localhost:8080"
}

有关如何解决该错误的任何建议?

javascript reactjs bootstrap-4
1个回答
9
投票

试试这个:

import 'bootstrap/dist/css/bootstrap.min.css';

如果未指定路径,Node / webpack将在node_modules文件夹中搜索导入。我不确定出了什么问题,但这是从node_modules文件夹导入模块的正确方法。

© www.soinside.com 2019 - 2024. All rights reserved.