Compilation of CSS by Webpack resulting in peculiar class identifiers

Currently, I am using webpack for developing a React app with a NodeJS backend.

I've encountered an issue with styling the app as webpack seems to be interfering with my CSS, causing changes in class names.

For example, in my base.css file, I have defined the following styles:

body {
  background: #ECEFF1;
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.7;
  margin: 0 auto;
  padding: 30px;  
  max-width: 980px;
}

.progress {
  background-color: #FFECB3;
}
.progress .indeterminate {
    background-color: #FFC107;
}

However, when I inspect the page and check the head section, the classes are transformed into something like this:

<style type="text/css">
body {
  background: #ECEFF1;
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.7;
  margin: 0 auto;
  padding: 30px;  
  max-width: 980px;
}

.base---progress---1RR8Z {
  background-color: #FFECB3;
}
.base---progress---1RR8Z .base---indeterminate---23sZH {
    background-color: #FFC107;
}

This transformation is causing issues with applying the progress styles correctly on the page. How can I prevent this or make React handle the class names appropriately?


If I remove the following from my webpack configuration:

{
      test: /\.css$/,
      loader: 'style!css?modules&localIdentName=[name]---[local]---[hash:base64:5]'
    }

An error occurs mentioning it cannot find the CSS file, even though the specified path is correct.


Providing the webpack configuration for reference:

'use strict';

var path = require('path');
var webpack = require('webpack');
var HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
  devtool: 'eval-source-map',
  entry: [
    'webpack-hot-middleware/client?reload=true',
    path.join(__dirname, 'public/app/main.js')
  ],
  output: {
    path: path.join(__dirname, '/dist/'),
    filename: '[name].js',
    publicPath: '/'
  },
  plugins: [
    new HtmlWebpackPlugin({
      template: 'public/app/index.html',
      inject: 'body',
      filename: 'index.html'
    }),
    new webpack.optimize.OccurrenceOrderPlugin(),
    new webpack.HotModuleReplacementPlugin(),
    new webpack.NoErrorsPlugin(),
    new webpack.DefinePlugin({
      'process.env.NODE_ENV': JSON.stringify('development')
    })
  ],
  module: {
    loaders: [{
      test: /\.jsx?$/,
      exclude: /node_modules/,
      loader: 'babel',
      query: {
        "presets": ["react", "es2015", "stage-0", "react-hmre"]
      }
    }, {
      test: /\.json?$/,
      loader: 'json'
    }, {
      test: /\.css$/,
      loader: 'style!css?modules&localIdentName=[name]---[local]---[hash:base64:5]'
    }]
  }
};

Answer №1

Currently, your configuration is utilizing css-modules. If you want to deactivate this feature, simply update the loader for css files from

'style!css?modules&localIdentName=[name]---[local]---[hash:base64:5]'
to 'style!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

The Link component in the router dom should only be active when validation passes successfully

I am looking for a way to prevent the Link component in react-router-dom from functioning until all validations are successfully completed. Removing the link allows the validation to work as intended. I have come across something related to ifValidate, bu ...

Toggling the form's value to true upon displaying the popup

I have developed an HTML page that handles the creation of new users on my website. Once a user is successfully created, I want to display a pop-up message confirming their creation. Although everything works fine, I had to add the attribute "onsubmit= re ...

Losing focus issue with Material-UI TextField occurs constantly with every onChange event

I am in the process of developing a new component: https://i.stack.imgur.com/czM9i.png This component will consist of an array of objects, each representing a prescription. Each object will include the medicine name selected from a dropdown and a text fi ...

The React Hook useEffect is missing a dependency: 'handleLogout'. Make sure to either add it to the dependency array or remove it from the useEffect hook

import { useState, useEffect } from "react"; import LoginModal from "./LoginModal"; import { NavLink, useLocation, useNavigate } from "react-router-dom"; import { useDispatch } from "react-redux"; import { userLogout ...

Even though I am not currently using socket.io, it continues to attempt to reconnect

I had previously set up a chatting server and then deleted it. As a result, I no longer have any files that use socket.io. 'use strict' const express = require('express') ,mongoose = require('mongoose') ,logger = ...

Concealing a hyperlink depending on the value chosen in a dropdown menu

Looking for guidance on how to use jQuery to read the current value of a drop-down list and hide a specific link based on that value. The drop-down list is for selecting the language/locale. For example, when "English" is selected, I want the link to be h ...

Incorporate Margins for Table Cells in Outlook (HTML Email)

I'm currently in the process of creating an email newsletter and testing it out on Litmus. Here's how the newsletter design should appear (refer to the image below): Although I understand that it may not look exactly the same on Outlook, is the ...

Share the Nav tag value or name during an OnClick event within ReactJS

I've been facing a minor issue that I just can't seem to figure out - how do I pass a value to my OnClick event? It's crucial for me to pass this value as it corresponds to the options in my menu and is essential for some processes: This is ...

Is there a way to halt or end an interval within a function triggered by useEffect()?

I am currently working on a countdown timer script using react.js. The timer displays a 3 or 5 seconds countdown before starting, with data for these countdowns coming from another component. I am facing an issue with controlling the main countdown timer ...

Utilize a component's CSS styles by inheriting them and applying them to another component

I have created custom styles for an object as shown below: form#sign_in{ position:relative; margin:85px auto 50px auto; width:455px; background:#fff; border:#dfdfdf 1px solid; border-radius:5px; -moz-border-radius:5px; -web ...

Angular4 - Div with ngIf doesn't respond to click event

I'm attempting to add a click event to a specific div. Within this div, there is another div that is dynamically generated based on a Boolean condition that I receive as input. Unfortunately, in this case, the click event is only functioning when clic ...

Discover the seamless process of retrieving user details from Postman API with a single click of the submit button on the front-end using Express and Node.js

Trying to display user input directly in Postman by submitting the submit button. This is my code: import express from "express"; import {dirname} from 'path'; import {fileURLToPath} from "url"; import bodyParser from "b ...

Disabling the current date on date pickers in material ui: A step-by-step guide

In my current React project, I am utilizing material-ui-date-pickers and need to prevent users from selecting today's date. This is important in the context of manufacturing products, managing expiration dates, and handling billing processes. Since a ...

Tell me the permissions that a user possesses in discord.js

I need help creating a command using Discord.js that can display a user's permissions. For instance, the command could be $permissions @user and it should output something like: "User permissions within this guild: " I'm unsure if ...

Using Google API, set up a Google Calendar event that includes a conference call feature

I am currently working on integrating Google Calendar events into my NodeJS application. While the code below successfully creates an event, it does not include a conference option. The response returned from the API does not contain any errors or inform ...

What could be the reason for ThemeProvider (Material UI) failing to function properly in this scenario?

I've encountered something puzzling with Material UI. Despite my experience with it, I can't seem to figure out why my H2 tag in the nested component is rendering in Times instead of Arial. I've double-checked the docs and my code, but the i ...

A guide to effectively utilizing a TypeScript cast in JSX/TSX components

When trying to cast TypeScript in a .tsx file, the compiler automatically interprets it as JSX. For example: (<HtmlInputElement> event.target).value You will receive an error message stating that: JSX element type 'HtmlInputElement' is ...

What is the best way to designate external dependencies in WebPack that are not imported using '*'?

I need assistance with specifying office-ui-fabric-react as an external dependency in my TypeScript project using Webpack. Currently, I am importing only the modules I require in my project: import { Dialog, DialogType, DialogFooter } from 'office-u ...

Leveraging Node.js MSSQL Module for Enhanced SQL Injection Security Measures

I've been exploring the built-in SQL injection protection feature in the MSSQL module for Node.js: https://www.npmjs.com/package/mssql#injection However, I'm a bit confused by their example on how to properly sanitize values for my queries. It ...

Leveraging NPM and MYSQL to transfer query outcomes to a different variable

I'm in need of assistance with a database package I'm developing for a larger application. The goal is to store specific data in a database using the mysql package in npm. However, I'm encountering an issue where the results variable always ...