Suemayah Eldursi
Suemayah Eldursi

Reputation: 1009

React-bootstrap elements does not have styling

I am working on a webapp using react.js and react-router and webpack. I would like to use react-bootstrap for styling but my navbar does not appear to be styled as shown here Navbar

this is my react-bootstrap code

<Navbar inverse fixedTop>
            
            <Navbar.Collapse>
            <Nav bsStyle="pills">
              <NavItem  href="#"><Link to="/">{this.state.navMenu[0] }</Link></NavItem>
              <NavItem  href="#"><Link to="/utilities">{this.state.navMenu[3] }</Link></NavItem>
              <NavItem  href="#"><Link to="/main">{this.state.navMenu[4] }</Link></NavItem>
            </Nav>             
            </Navbar.Collapse>
          </Navbar>

these are the dependencies

"devDependencies": {
"babel-cli": "^6.4.0",
"babel-core": "^6.4.0",
"babel-polyfill": "^6.3.14",
"babel-preset-es2015": "^6.3.13",
"babel-preset-react": "^6.3.13",
"babel-preset-stage-0": "^6.3.13",
"css-loader": "^0.23.1",
"file-loader": "^0.8.5",
"history": "^1.17.0",
"react": "^0.14.6",
"react-dom": "^0.14.6",
"style-loader": "^0.13.0",
"webpack": "^1.12.11",
"webpack-dev-server": "^1.14.1"},

  "dependencies": {
    "bootstrap": "^3.3.6",
    "imports-loader": "^0.6.5",
    "react": "^0.14.6",
    "react-bootstrap": "^0.28.2",
    "react-router": "^2.0.0-rc5"
  }

and this is the webpack.config file

var webpack = require('webpack');  
module.exports = {  
    entry: [
      'babel-polyfill',
      'webpack/hot/only-dev-server',
      "./app.js",
    ],
    output: {
        path: __dirname + '/build',
        filename: "bundle.js"
    },
    module: {
        loaders: [
            { test: /\.jsx?$/, loaders: ['react-hot', 'babel'], exclude: /node_modules/},
            { test: [/\.jsx?$/, /\.es6$/], exclude: /node_modules/, loader: 'babel-loader'  },
            { test: /\.css$/, loader: 'style!css' },
        ]
    },
     resolve: {
    // you can now require('file') instead of require('file.coffee')
    extensions: ['', '.js', '.json', '.coffee'] 
    },
    plugins: [
      new webpack.NoErrorsPlugin(),
      
    ]

};

Ive tried to require 'bootstrap' but I get the following error: Uncaught ReferenceError: jQuery is not defined

any help is greatly appreciated please.

Upvotes: 8

Views: 8040

Answers (2)

BWildish
BWildish

Reputation: 21

An update some may find useful: make sure you install bootstrap v3.3.7 (npm install --save [email protected]) and not the newest version 4 because react-bootstrap targets the CSS in v3. Many of the styles, such as those for the navbar, don't exist in the CSS for v4.

Upvotes: 2

Krzysztof Sztompka
Krzysztof Sztompka

Reputation: 7204

You shouldn't include bootstrap, because it will include in your project all bootstrap js files (they have as dependency jquery - therefore you get error). You don't need bootstrap js files, because you use react-bootstrap instead.

To include all css files from bootstrap write :

import style from 'bootstrap/dist/css/bootstrap.css';

After that you will also have problem with additional loaders. This is because, bootstrap styles use other files too.

Install:

npm install --save-dev url-loader

And you have to add to webpack configuration loader:

{
  test: /\.(png|woff|woff2|eot|ttf|svg)$/,
  loader: 'url-loader?limit=100000'
},

In style-loader documentation page, author recommend to use style-loader with css-loader. Change this:

{ test: /\.css$/, loader: 'style!css' },

Upvotes: 10

Related Questions