I just went through this, and seems that there are lot of people lost or not finding the right answer. This is what I did:

Get control over the configuration

npm run eject

Running this command will copy all the configuration files and the transitive dependencies (Webpack, Babel, ESLint, etc) right into your project, as you noted all that was inside a npm module called react-script. Do not modify this package directly!

Install sass compiler and webpack loader

npm install sass-loader node-sass --save-dev

At this point you have to install the sass compiler and the webpack loader as development dependencies.

Modify the webpack configuration

  1. Open config\webpack.config.dev.js.
  2. Add /\.scss$/, to the exclude array in the url loader, it will look something like this after the update:

    exclude: [
        /\.html$/,
        /\.(js|jsx)$/,
        /\.css$/,
        /\.json$/,
        /\.svg$/,
        /\.scss$/, //Add this line
    ],
    
  3. Add the SASS/SCSS loader:

    {
        test: /\.scss$/,
        loaders: ['style', 'css', 'sass']
    },
    
Answer from Tomas Ramirez Sarduy on Stack Overflow
🌐
GitHub
github.com › wmonk › create-react-app-typescript › issues › 95
SCSS compiling but styles not applied · Issue #95 · wmonk/create-react-app-typescript
July 2, 2017 - { test: /\.tsx?$/, loader: ["react-hot-loader/webpack", "awesome-typescript-loader"] }, { test: /\.css$/, loader: stylesLoader }, { test: /\.scss$/, use: [ { loader: "style-loader" // creates style nodes from JS strings }, { loader: "css-loader", options: { sourceMap: true } }, { loader: "sass-loader", options: { sourceMap: true } } ] }, { test: /\.svg/, use: [ { loader: "svg-url-loader", options: { dataUrlLimit: 1024 } }, { loader: "svgo-loader", options: { plugins: [ { removeTitle: true }, { convertColors: { shorthex: false } }, { convertPathData: false } ] } } ] }, // All output '.js' files will have any sourcemaps re-processed by 'source-map-loader'.
Author   jrmcdona
🌐
DhiWise
dhiwise.com › post › troubleshooting-guide-how-to-fix-react-css-not-applying
Troubleshooting Guide: Resolving React CSS Not Applying
May 30, 2024 - To ensure your CSS file is applied, it must be correctly imported into your React components. This typically involves adding an import statement at the top of your JS file. ... Ensure that the relative path to your CSS file is correct.
🌐
Reddit
reddit.com › r/reactjs › having trouble getting scss working in react
r/reactjs on Reddit: Having trouble getting scss working in react
April 30, 2017 -

Hi,

So i've recently created a new react app using

$ npm create-react-app
$ npm run eject
$ npm install sass-loader style-loader css-loader --save-dev

I changed the default .css files to be .scss, and changed the default imports to be importing the '.scss' file instead of a '.css' file.

My webpack.config.dev.js looks like this: https://gist.github.com/VirtuallyBookish/9a0e851268061d9e5325ebe872f5c91e

But whenever I attempt to run the app using:

$ npm run start

I'm greeted with an error like this (or similar): ./src/index.js Module not found: Can't resolve 'style' in '/Users/usr_name/Sites/react/app-demo'

I was following this tutorial for adding it: https://medium.com/@gpickett00/didnt-work-for-me-22e05f97b5a7

I've been struggling on this for a while, so any help would be massively appreciated! Thank you!

EDIT:

I sorted this out I think! I changed the line that read:

loaders: ['style', 'css', 'sass']

to

loaders: ['style-loader', 'css-loader', 'sass-loader']
🌐
Pluralsight
pluralsight.com › tech insights & how-to guides › tech guides & tutorials
Solving the React Error: Not Picking Up CSS Style | Pluralsight
import React, {Component} from 'react'; import ReactDOM from 'react-dom'; import '../src/CSS_Files/style.css'; A path reflects the address of a file, so a wrong path can easily produce an error without you noticing it. Consider an example: Suppose you are importing a CSS file into your React program.
🌐
Reddit
reddit.com › r/react › css style not applying
r/react on Reddit: CSS style not applying
March 4, 2023 -

Hello, this is my first time working with React and I'm running into some issues.

I created a CSS file but it is not applying the styles when I use className or id. However it is applying the style when I use only

the html elements (i.e. h1, input, ul, etc).

I saved the css file in the src folder and wrote the import statement so I am very confused as to what's going on.

Please let me know if further information is needed and thank you in advance!

🌐
GitHub
github.com › facebook › create-react-app › issues › 13597
CSS is not working correctly after applying the React code Splitting. · Issue #13597 · facebook/create-react-app
May 23, 2024 - I have created my react app using the CRA and I recently added the react code splitting to it. After adding it, my CSS is not working properly. So if I have a search component that I have included in code splitting. When I navigate to it...
Published   May 23, 2024
Author   lalit-tudip
Find elsewhere
🌐
Stack Overflow
stackoverflow.com › questions › 65096721 › react-js-is-not-applying-styles-from-my-sass-file
reactjs - React.js is not applying styles from my .sass file - Stack Overflow
I created this with create-react-app. I used NPM to install sass (version 4 I think). I don't get any errors in the console or command line window. ... I reinstalled node-sass. Still get the same result, no styles. ... I also changed the file back to just styles.css and wrote import "./style/styles.css"; in my app.js . Still nothing. ... Ok, the problem was that somehow, something deleted all the text in my .scss file.
🌐
MDBootstrap
mdbootstrap.com › standard › material design for bootstrap 5 & vanilla javascript
Stylesheet not applying - Material Design for Bootstrap
June 17, 2021 - Style sheet does not apply. ... Keep coding! ... On this part of the tutorial it says to install it as a package and then copy the folder containing the styles into the asset folder. I followed all the instructions correctly. Is token generation mandatory? If so I haven't set that up. ... No, the token is needed for the pro version when you are installing mdbreact with npm. Are you sure that you copied all of the SCSS files from node_modules?
Top answer
1 of 7
13

In a react project created with create-react-app or npx create-react-app, I also had the same issue.

I had imported index.css file in my App Component but my styles were not being applied properly to my React Components.

I even tried directly adding index.css file in my html file in the public folder and using link tag to link to my index.css file (which resides within src folder).

<link rel="stylesheet" href="./../src/index.css">

That also didn't work.

Finally, I read an article about 7 ways to apply CSS into React. One best way was to install node-sass into our project and use index.scss ( import './index.scss') into App Component instead of index.css.

And Hurray!!! My CSS worked fine, All the Media Queries started to work fine.

Below is the code snippet you can try.

import React from "react";
import ReactDom from "react-dom";
import './index.scss';


// --- Data to work with ---
const books = [
  {
    id: 1,
    name: 'The Rudest Book Ever',
    author: 'Shwetabh Gangwar',
    img: 'https://m.media-amazon.com/images/I/81Rift0ymZL._AC_UY218_.jpg'
  },
  {
    id: 2,
    name: 'The Rudest Book Ever',
    author: 'Shwetabh Gangwar',
    img: 'https://m.media-amazon.com/images/I/81Rift0ymZL._AC_UY218_.jpg'
  },
  {
    id: 3,
    name: 'The Rudest Book Ever',
    author: 'Shwetabh Gangwar',
    img: 'https://m.media-amazon.com/images/I/81Rift0ymZL._AC_UY218_.jpg'
  },
  {
    id: 4,
    name: 'The Rudest Book Ever',
    author: 'Shwetabh Gangwar',
    img: 'https://m.media-amazon.com/images/I/81Rift0ymZL._AC_UY218_.jpg'
  },
];


const Book = ({ book }) => {
  return (
    <div className={"book"}>

      <img src={book.img} alt="book image" />

      <h3>{book.name}</h3>
      <p>{book.author}</p>
    </div>
  )
};

const Books = () => {
  return (
    <main className={"books"}>
      {
        books.map(book => {
          return (<Book book={book} key={book.id} />)
        })
      }
    </main>
  )
};


// Work a bit fast | one step at a time
const App = () => {
  return (
    <main>
      <h2>Books</h2>
      <Books />
    </main>
  )
}

ReactDom.render(<App />, document.getElementById("root"));
/* --- Mobile First Design --- */
.books{
  text-align: center;
};

.book{
  border: 1px solid #ccc;
  text-align: center;
  width: 200px;
  padding: 1rem;
  background: #001a6e; 
  color: #fff;
  margin:auto;
};

h2{
  text-align: center;
}

/* --- Adding Media Queries --- */
@media only screen and (min-width: 900px){
  .books,.persons{
    display:grid;
    grid-template-columns: 1fr 1fr;
  }
}

To install node-sass, simple do npm install node-sass --save Then rename all your .css files with .scss and your project with work properly.

The package.json should have the node-sass dependency added as shown below:

 "dependencies": {
    "node-sass": "^4.14.1",
    "react": "^16.8.3",
    "react-dom": "^16.8.3",
    "react-scripts": "2.1.5"
  },

Hope this will help many developers :)

2 of 7
4

It would be helpful to see your React component as well.

Given this code, you are passing className as a property into the component rather than assigning a class to it:

export default class App extends Component {

  constructor(props) {
    super(props);
    this.state = {
      data: null
    };
  }

  render() {
    return (
      <div>
        /** This line specifically **/
        <ContactList className="contactList" />
        <ContactDetail />
        <AddContactModal />
      </div>
    );
  }
}

Inside your component, you would need to use className={this.props.className} on a regular HTML tag inside of your component in order to pass the className through.

🌐
Medium
medium.com › @oreofeolurin › configuring-scss-with-react-create-react-app-1f563f862724
How to Configure React with SASS/SCSS (create-react-app) | by Olurin Oreofe | Medium
November 5, 2018 - How to Configure React with SASS/SCSS (create-react-app) NOTE: For latest version of create-react-app (since react-scripts@2.0.0) all you need to do is install node-sass and import a file with the …
🌐
W3Schools
w3schools.com › react › react_sass_styling.asp
React Sass Styling
In the newly created .scss file, add some simple styling: ... import { createRoot } from 'react-dom/client'; import './MyStyle.scss'; function MyHeader() { return ( <h1>My Header</h1> ); } createRoot(document.getElementById('root')).render( <MyHeader /> );
🌐
GitHub
github.com › facebook › create-react-app › issues › 5040
Sass files seems like it's not working when import from *.scss instead of *.css · Issue #5040 · facebook/create-react-app
September 20, 2018 - ... "scripts": { "start-js": "react-scripts start", "start": "npm-run-all -p watch-css start-js", "watch-css": "npm run build-css && node-sass-chokidar --include-path ./src --include-path ./node_modules src/ -o src/ --watch --recursive", "build-css": "node-sass-chokidar --include-path ./src --include-path ./node_modules src/ -o src/", "build-js": "react-scripts build", "build": "npm-run-all build-css build-js" } ... change all *.css files to *.scss · Should be work the styles form .scss files the same way as it did with .css files · It's not applying the scss files changes ·
Author   Jero786
🌐
Quora
quora.com › Why-is-React-not-reading-a-CSS-file-React-js
Why is React not reading a CSS file (React.js)? - Quora
Answer: This is not a React problem, it is either a loading or css (class specificity, etc) problem. In the css file, add an [code ]!important[/code] css rule to turn all text red, targeting the body tag.