question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

sass CSS Module Not Working

See original GitHub issue

Bug report

Describe the bug

I am trying to use a sass CSS module, however I do not see the styles taking effect on the page. I followed instructions both here: https://nextjs.org/blog/next-9-3#built-in-sass-css-module-support-for-component-level-styles and here: https://nextjs.org/docs/basic-features/built-in-css-support#adding-component-level-css however the styles do not take effect.

To Reproduce

  • Install sass
  • Create a file [name].module.scss
  • Import that file from inside the component [name]
  • Add styles.[className] to the className prop

./components/Header.module.scss

.header {
    border: 1px solid red;
    height: 4.0rem;
    background-color: #fff;
    box-shadow: inset 0px -1px 0px rgba(0, 0, 0, 0.16);
}

./components/Header.tsx

import style from "./Header.module.scss";
export default function Header() {
  return (
    <div className={style.header}>
      <p>Logo</p>
    </div>
  );
}

next.config.js

module.exports = {
  poweredByHeader: false
};

Expected behavior

I expect the Header component to have the styles applied.

System information

  • OS: macOs
  • Browser: chrome
  • Version of Next.js: 9.3.1
  • Version of sass: 1.26.3

Additional context

In the dev tools, I see the random class name assigned to the component: image however the ''header" class is not applied, and even if i add the class manually in the dev tools, i do not see the styles applied.

Any guidance here is much appreciated!

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:6
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

11reactions
cbonaco1commented, Mar 22, 2020

I currently am no longer facing this issue. I logged style object and style.header is in fact a string. Several updates have been made to my project since i reported this issue, so it’s difficult to track down what fixed it. I’ll close this issue and re-open if I come across it again.

0reactions
balazsorban44commented, Jan 28, 2022

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

Read more comments on GitHub >

github_iconTop Results From Across the Web

CSS modules not working for react version 16.6.0
I had this same problem and solved it by renaming my css file to: myName.module.css. and also importing like this: import styles from...
Read more >
How to use Sass and CSS Modules with create-react-app
A CSS Module is a CSS file in which all class names and animation names are scoped locally by default. Basically, same class...
Read more >
How to Use Sass with CSS Modules in Next.js - freeCodeCamp
CSS Modules are essentially CSS files that, when imported into JavaScript projects, provide styles that are scoped to that particular part of ...
Read more >
How I integrated CSS Modules with SCSS into my React ...
CSS Modules allow you to have modular styling in your components. This means no more conflicts of classNames within your application. Meanwhile, SCSS...
Read more >
Setup React CSS Modules (with SASS, multiple classes and ...
In this tutorial I want to show you a few tips on how to setup modular scopes css along with setting up sass...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found