Adding a CSS file in ReactJS is not possible for both Bootstrap and Stylesheet

While working on my React JS project, I encountered an error when trying to include both my custom styles and Bootstrap. The error message states: "Refused to apply style from 'http://localhost:8000/bootstrap-3.3.7-dist/css/bootstrap.min.css' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled."

I prefer inserting Bootstrap through the index.html file as it's what I am accustomed to. Even though I am aware of other methods like using npm and importing Bootstrap, I still want to stick with embedding it in the index.html.

Below is the hierarchy of files:

https://i.sstatic.net/t6fSU.png

Here are the relevant sections of my code:

INDEX.HTML

<!DOCTYPE html>
<html lang="en">
    <head>
        <title>Ticketing</title>

        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">

        <!-- Tell the browser to be responsive to screen width -->
        <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">

        <link rel="stylesheet" type="text/css" href="./bootstrap-3.3.7-dist/css/bootstrap.min.css"/>
        <link rel="stylesheet" type="text/css" href="./style/style.css" />
    </head>
    <body>
        <div id="app"></div>
        <script src="/app/bundle.js"></script>
    </body>
</html>

WEBPACK.CONFIG.JS

var webpack = require("webpack");
var path = require("path");

var DIST_DIR = path.resolve(__dirname, "dist");
var SRC_DIR = path.resolve(__dirname, "src");

var config = {
    entry: SRC_DIR + "/app/index.js",
    output: {
        path: DIST_DIR + "/app",
        filename: "bundle.js",
        publicPath: "/app/"
    },
    module:{
        loaders: [
            {
                test: /\.js?/,
                include: SRC_DIR,
                loader: "babel-loader",
                query:{
                    presets: ["react", "es2015", "stage-2"]
                }
            }
        ]
    }
};

module.exports = config;

Answer №1

In my opinion, relocating the css and style directories to the src directory would be a good idea. Alternatively, you could experiment with replacing ./ with ../.

Answer №2

To obtain it, utilize the following method: Firstly, install Bootstrap via npm (npm i bootstrap),

Then navigate to your app.js file and insert:

@import '../node_modules/bootstrap/dist/css/bootstrap.min.css' @import 'YOUR_CSS_FILE.css'

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

Is there a way for me to access the source code of elements within React Native?

Currently, I am working on writing code using React Native and compiling it in Android Studio with an emulator. When I press ctrl+m on the emulator and select "show inspector" to click on elements, I am unable to see which line of code corresponds to the s ...

Error message: CORS policy prevents third-party scripts from running in Next.js

I am encountering an issue with implementing a script handling tool in my Next.js project. I followed the documentation on nextjs.org and utilized the worker (experimental) parameter to enhance the page's performance. However, I am facing a CORS polic ...

Design an interactive listbox with both HTML and Angular that allows for multiple selections

I am trying to implement a multi select listbox with keyboard navigation capability. Currently, this is the HTML layout I have: <div> <div *ngFor="let tag of tags; let index=index" [class.selectedRow]="rowIsSelected(tag.id) ...

Is there a way to incorporate TypeScript type definitions into a JavaScript module without fully transitioning to TypeScript?

Although the title may be a bit confusing, it encapsulates my query in a succinct manner. So, here's what I'm aiming to achieve: I currently have an npm module written in JavaScript, not TypeScript. Some of the users of this module prefer using ...

Tips on transferring information from a component to an instance in Vue

My goal is to retrieve data from a component and transfer it to a variable within my root Vue instance. Vue Instance Configuration: new Vue({ el: '#root', data: { searchResultObject: '' }, methods: { // ...

Adaptable data table featuring varying sizes of columns and rows

I'm attempting to design a grid that resembles the following: https://i.sstatic.net/Sf7M9.png The challenge I'm facing is how to ensure that the column and row names adjust properly with the grid in the center. Currently, this is the code I hav ...

Experiencing difficulty with the toggle menu on an HTML/CSS website. Unable to access the menu when hovering over the hamburger icon on the right side

I am experiencing an issue with the toggle button in the menu when the screen size is max-width = 1200px. Specifically, when I toggle the button, nothing appears. Can someone please assist me? I have included Bootstrap 4.3 in my HTML script. The menu that ...

Failure to Reach AngularJS ng-click Function

When trying to add a new product to the product list, I am facing an issue. The products load correctly but the ng-click function is not being triggered. (The alert I set up in the addProduct function is not appearing). HTML <div ng-controller="Produc ...

Efficiently sift through a vast assortment using a filtering method

Currently, I am developing an application similar to Uber which involves managing a collection of drivers with their current positions (latitude and longitude). One specific requirement is to find drivers who are within a 200-meter distance from the user& ...

How can I incorporate a custom icon into the <i> tag in HTML like Bootstrap does with its icons?

When working with Bootstrap, you can easily add an icon using the following syntax: <i class="bi bi-arrow-right-square-fill fs-1"></i> One great feature is that you can adjust the size of the icon by simply adding the fs-1 class. If ...

The Discord.js script fails to send embedded messages as intended

Issue with sending embedded messages using Discord.js code Embed code not functioning properly: Error code received: ...

The links located beneath the iframe/span element are unclickable

My latest creation is a static advert ticker positioned at the bottom of the window. It's contained within an <iframe> for easy placement on other websites. I added a <span> around the <iframe> to keep it fixed at the bottom of the s ...

Clarification: Obtain the state prior to the current one

I've been diving into the React Documentation and came across a topic that I'm struggling to grasp fully: https://reactjs.org/docs/hooks-faq.html#how-to-get-the-previous-props-or-state function Counter() { const [count, setCount] = useState(0) ...

The JSONLoader object successfully links to a URL but encounters issues with relative paths

Currently facing a minor but persistent issue with THREE.js and seeking assistance. Upon observation, I've discovered that linking a three.js 3D object using an URL functions properly. However, when a relative path is used, only a black window appear ...

Tips for properly panning across the canvas

I added event listeners to capture mouse movement, clicks, and releases in my code. canvas.addEventListener('mousemove', onMouseMove, false); canvas.addEventListener('mousedown', onMouseDown,false); canvas.addEventListener('mouseu ...

Processing one file to submit two forms to the database in Express

I am facing an issue with two forms on one form.hbs page using the same process.js file. Each form is processed by a different submit button for separate occasions. The first submit button works correctly, processing the data in the process.js file and se ...

Is there a way to seamlessly transition between images in a slider every 3 seconds using javascript?

<!DOCTYPE html> <html> <head> <title>Hello</title> <meta http-equiv="Content-Type" type="text/html" charset="UTF-8"/> <style> *{margin:0; padding:0;} .mySlides{ position:relative; width:1000px; ...

Does NextJs have a feature or function similar to the createRef() hook found in traditional ReactJs?

Trying to utilize a 3rd party package called ReactPhotoSphereViewer in NextJs to showcase panoramic images on the website. The package functions well in both NextJs and ReactJs. Below is the code that functions in ReactJs: import { ReactPhotoSphereViewer ...

supplying various color variables to a single class

I am working on a webpage with multiple elements sharing the same CSS class. I want each element to have a unique background color, but I don't want to create a bloated CSS file. Is there a way to achieve this by adding a parameter in my HTML like cla ...

Ways to convert a JavaScript object into restful GET parameters in order to append them to the end of an API URL

Suppose we have a JSON object like this: { name: 'Tony', age: '20', birthday: '20180101', } What is the best way to convert it into parameters that can be appended at the end of a RESTful GET API URL, such as the ...