sass CSS Module Not Working
See original GitHub issueBug 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 theclassNameprop
./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:
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:
- Created 4 years ago
- Reactions:6
- Comments:7 (2 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

I currently am no longer facing this issue. I logged
styleobject andstyle.headeris 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.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.