I am trying to use react-bootstrap-table2 in my project to create a simple bootstrap table, but am getting the error:
Failed to Compile: Module not found: Can't resolve '../node_modules/bootstrap/dist/css/bootstrap.min.css' in '/Users/xxx/Documents/xxx/src/routes/home'.
I did install all the necessary packages and verified that bootstrap.min.css exists where it should.
My code looks like this:
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;
My package.json file looks like this:
{
"name": "codist",
"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"
}
Any suggestions for how to resolve that error?
I am trying to use react-bootstrap-table2 in my project to create a simple bootstrap table, but am getting the error:
Failed to Compile: Module not found: Can't resolve '../node_modules/bootstrap/dist/css/bootstrap.min.css' in '/Users/xxx/Documents/xxx/src/routes/home'.
I did install all the necessary packages and verified that bootstrap.min.css exists where it should.
My code looks like this:
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;
My package.json file looks like this:
{
"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"
}
Any suggestions for how to resolve that error?
Share Improve this question edited Aug 29, 2018 at 16:42 n8o 1,9433 gold badges24 silver badges41 bronze badges asked Aug 29, 2018 at 15:30 arcade16arcade16 1,5354 gold badges25 silver badges46 bronze badges 1 |2 Answers
Reset to default 18Try this:
import 'bootstrap/dist/css/bootstrap.min.css';
When not specifying a path, Node/webpack will search for the import inside node_modules
folder. I'm not sure what's going wrong, but this is the correct way to import modules from the node_modules
folder.
If you are using VS code use "node_modules/bootstrap/dist/css/bootstrap.min.css" in styles for angular.json
node_modules
does not need the path prefix. – n8o Commented Aug 29, 2018 at 15:34