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 NodeJS module 'request' is producing symbols instead of expected HTML content

Currently, I am delving into the world of Nodejs and experimenting with web scraping using node.js. My tools of choice are the node modules request and cheerio. However, when I attempt to request a URL, instead of receiving the HTML body, I get strange s ...

A comprehensive guide on utilizing the loading.tsx file in Next JS

In the OnboardingForm.tsx component, I have a straightforward function to handle form data. async function handleFormData(formData: FormData) { const result = await createUserFromForm( formData, clerkUserId as string, emailAddress a ...

Creating a static webpage hosted in an S3 bucket and implementing an AJAX request within the page to invoke a Lambda function

I recently uploaded an HTML page to an S3 bucket that includes an AJAX post request to the API Gateway URL in order to send an email. The issue arises when I try to use the same API Gateway URL with Postman to make a post request for sending emails, it wo ...

The CSS class names for Next.js have not been defined yet

Just getting started with next js and trying to use css modules for styling my nav component. However, I noticed that the classname I setup for the nav element is not showing up in the rendered DOM. Even though I can see the generated styles by webpack in ...

Illuminate the current page

I have been working on a website with around 20 pages that all have a side navigation bar. To make it easier to manage, I decided to centralize the links in a JavaScript (JS) file and include it on each HTML page. This way, any changes can be made quickly ...

Is there a way to generate a distinctive curved design using CSS for a

I am currently using CSS and div elements in an attempt to create these particular lines: https://i.stack.imgur.com/Ytowq.png .line { width: 1px; height: 100px; background-color: black; position: absolute; border-radius: 50%/100px 1 ...

The refresh function in the table is not working as expected when implemented in a functional component. The table being used is Material

I am currently utilizing MaterialTable from https://material-table.com/#/docs/features/editable to manage data and perform CRUD operations within my application. I am seeking a way to automatically refresh the table data after any CRUD operation (add, upda ...

Could you walk me through the details of this React function?

Currently, I have a function in place that retrieves products from the database to display on the eCommerce website's product page. Now, I am working on creating a similar function for user sign-in. Could you lend me a hand with this? I'm still ...

Guide to sending FCM notifications with node.js specifically to a specific package name

I have been working diligently on a project that heavily relies on Firebase. I have successfully implemented all the necessary Firebase functionalities for the consumer app and admin app, except for FCM (Firebase Cloud Messaging). My goal is to notify the ...

Any tips for customizing the appearance of a {Switch} component from react-router-dom? I attempted to encase it in a <div> element, but it did

https://i.stack.imgur.com/4piCG.jpg https://i.stack.imgur.com/CyQH3.jpg My code attempts to modify the styling of the map component, but it seems to be influenced by the Switch component. How can I ensure that the screen fits within the 'root' ...

Struggling with getting the exceljs node.js write file function to work on my VPS, even though it works perfectly

After creating an excel file using this repository: https://github.com/guyonroche/exceljs#create-a-workbook, I encountered a strange issue. When saving the file on my localhost, everything works perfectly fine - the file is created and can be opened, read, ...

Is your Facebook send button appearing strangely? Find out how to fix it here!

I recently integrated the Facebook send button on my website, allowing users to easily share information about each drive listed. However, a new issue has arisen where clicking on the send button opens a popup inside a table, negatively affecting the page& ...

Using JavaScript to print radio type buttons

Currently working on a web page and I've encountered a problem that's got me stumped. There are two sets of radio buttons - the first set for package dimensions and the second set for weight. The values from these buttons are assigned to variable ...

Error: Unexpected token '<' found while using Next.js middleware, causing a SyntaxError

I have implemented a Next.js middleware that redirects to the login page if there is no available token from the Spotify API. This is how my middleware looks: import { getToken } from "next-auth/jwt"; import { NextResponse } from "next/serv ...

Creating a loading spinner in a Bootstrap 5 modal while making an XMLHttpRequest

While working on a xmlhttprequest in JavaScript, I incorporated a bootstrap spinner within a modal to indicate loading. The modal toggles correctly, but I am struggling to hide it once the loading is complete. I prefer using vanilla JavaScript for this ta ...

Use one tag to abbreviate multiple times

As I create a step-by-step guide, I want the audience to be able to hover over any word in the text and see its definition. However, I only want to define abbreviations once. Is there a method in html or css that allows me to achieve this? ...

Unusual class exhibiting peculiar async/await patterns

Node 7.9.0 The situation goes like this: class TestClass { constructor() { const x = await this.asyncFunc() console.log(x) } async asyncFunc() { return new Promise((accept) => { setTimeout(() => accept("done"), 1000) }) ...

Incorporating HTML5 audio elements in JavaScript

I am working on a project where I need to create a grid of 16 audio files with separate links for each in HTML, CSS and JavaScript. Each box in the grid should link to a different audio file. My initial thought was to use a table to achieve this, so I cre ...

Unable to access the response body of a POST request from an external API within Firebase Cloud Functions

I am encountering an issue with my cloud function in which it makes an http POST request to the LinkedIn API for retrieving an access token. The main problem is that I am unable to retrieve the `body` of the response as it always turns out to be `undefined ...

Is it possible to streamline the restart process in my game and eliminate the extra unnecessary click?

This game requires you to click each image once without clicking one twice. The issue arises when trying to reset the game after all images are clicked. Currently, it requires an extra random click after all 12 images have been clicked in order to render t ...