The React-bootstrap components lack predefined styles

I have been working on a web application using react.js, react-router, and webpack. I wanted to style it using react-bootstrap for the navbar, but it seems that my navbar is not getting styled properly as shown in the documentation here

Here is the react-bootstrap code I am using:

<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>

Below 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"
  }

Here 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(),
      
    ]

};

I've attempted to require 'bootstrap' but encountered this error: Uncaught ReferenceError: jQuery is not defined

Any assistance would be greatly appreciated.

Answer №1

Avoid including bootstrap in your project as it will add all bootstrap js files, which have a dependency on jQuery causing errors. Instead, opt for react-bootstrap without the need for bootstrap js files.

To include all CSS files from bootstrap:

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

You may encounter issues with additional loaders due to bootstrap styles using other files.

Resolve this by installing:

npm install --save-dev url-loader

Don't forget to update your webpack configuration loader:

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

The author of the style-loader documentation suggests using style-loader with css-loader. Update to:

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

Answer №2

For those seeking an update: It is important to ensure that you are installing bootstrap version 3.3.7 (npm install --save [email protected]) instead of the latest version 4, as react-bootstrap is designed for CSS in version 3. Version 4 does not include many styles present in version 3, such as those needed for the navbar.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

How can I retrieve the URL of images listed in my CSS file using Python?

I need help extracting all image URLs used in a CSS file. Here is an example snippet from my CSS file: sitewrap { width: 890px; margin: 0 auto; background: #ffffff url(../images/bg_sitewrap.gif) repeat-y; } Can anyone advise on how to extract ...

Navigate between pictures using hover in jQuery

I am working on creating a feature where images cycle through individually every 2 seconds, but switch to the right image when its associated link is hovered. So far, I have managed to make the images show up on hover, but I am struggling with getting them ...

Acquire the worth of the <MenuItem> element from React's mui/material library

I am attempting to retrieve the value of the selected item listed below: Here is my attempt at logging this information: console.log("Event: ", event.currentTarget); Output: <li class="MuiButtonBase-root MuiMenuItem-root MuiMenuItem-gut ...

Firefox failing to display fonts from Google Font API

The landing page our company outsourced does not display the Lato font in Firefox, resorting to a different option instead. We have received a stylesheet from fonts.googleapis.com that includes the following: @font-face { font-family: 'Lato'; ...

Enhance your FullCalendar experience with React by displaying extra information on your calendar

I am new to using React and FullCalendar, and I have a page layout similar to the image linked below. https://i.sstatic.net/MooTR.png Additionally, I have a list of events structured as shown: id: "9", eventId: "1", ...

React error message: "Cannot update state on a component that is not mounted" unless using the useEffect hook

(I am a beginner using Next.js + Styled Components and need help :)) I'm currently working on creating a "Netflix" style page, with unique catalog components. Each content item in the grid is a complex component named ContentItem.js that is repeated ...

What is the purpose of specifying http://localhost:3000 when accessing API routes in Next.js?

I created an API route within the pages directory of my NextJS project. It is functioning properly as I am able to retrieve data by directly accessing the URL like http://localhost:3000/api/tv/popular. My goal is to fetch this data using getStaticProps and ...

Creating a customized component using unique styles in Material UI version 1

Currently, I am facing a challenge in styling my Card component with a width of 75 pixels while using Redux and Material UI V1. Despite following the example provided by Material UI on custom styling through withStyles and connect, I have not been able to ...

Tips for modifying the background color of all elements ahead of the element I have selected within a grid

https://i.stack.imgur.com/cW4Lp.png I'm trying to achieve a functionality where clicking on the 20th numbered block changes everything before it to light orange. I have a sandbox code snippet attached and would appreciate any guidance on what needs t ...

Is it possible to trigger useEffect using an onClick event?

const example = () => { useEffect(() => { setState("example") }, [exampleDependency]) } <button onClick={() => Example()}>click me</button> Hey everyone, I'm attempting to execute this function, but I'm ...

The changes made in the CSS file are not reflected in the browser

Recently, I encountered a strange issue with my new server where the CSS changes were not reflecting in the browser. Despite trying to refresh and clear the cache, the problem persisted. To investigate further, I used FileZilla to check if the updated CSS ...

CodeMirror's styling becomes inconsistent during state changes or component re-renders in Next.js. Although everything appears to function correctly during development, issues arise in production

In my current Nextjs project, I am utilizing react-codemirror version ^4.20.2. While everything works perfectly in the development environment, once I deploy the app on Vercel, the Codemirror component experiences appearance and styling issues upon re-rend ...

JavaScript offers a variety of options for creating a link-styled button

Is there a distinction between <a href="javascript:;"></a> and <a href="javascript:void(0);"></a> ? I am looking to create a link-styled button that triggers a JavaScript function when clicked, so I implement the following: ...

Having trouble with importing files from a different folder in a React Typescript project

I have a specific folder arrangement set up https://i.sstatic.net/GFOYv.png My goal is to bring both MessageList.tsx and MessageSent.tsx into my Chat.tsx file // Chat.tsx import React from 'react' import {MessageList, MessageSent} from "./ ...

The HTTP connection established between the ReactSample and the AsP.NET Core WebApi

My current setup involves using axios to make HTTP requests in the frontend. async componentDidMount() { const { data: posts } = await axios.get("http://localhost:58944/api/posts"); this.setState({ posts }); } When the backend receives a request from the ...

Establishing the state using React in conjunction with TypeScript

Struggling to understand how to utilize TypeScript to set the state of my React component. Currently developing a basic Todo list Creating a component for the entire list named: TodoList Desire to populate the list with initial items for testing purpos ...

Aligning an image in a way that adjusts to different screen sizes

Struggling with centering an image horizontally in a responsive manner while using Bootstrap v3.3.5? Here's my code: <div class="container"> <div style="margin:0 auto;"> <img src="images/logo.png" alt="logo" /> ...

How can I set environment variables while running a Node application with webpack-dev-server?

When working on my node application, I am facing an issue with distinguishing between the development version and production version. To run webpack-dev-server, I utilize the following command: NODE_ENV=development webpack-dev-server --inline --hot --cont ...

A guide on loading modules dynamically using React and Typescript from a server

I am working on a React / Typescript / Webpack / React-Router application that contains some large JS modules. Currently, I have two bundles (common.js and app.js) included on every page, with common.js being a CommonsChunkPlugin bundle. However, there is ...

Steps to create a translating floating chat button on your website

Hello there! I am attempting to replicate the style of a Floating Website Chat Button. When a user clicks on the large button, I want it to disappear and transform into a chat box. Something similar to this example: https://codepen.io/neilkalman/pen/VPJpaW ...