Styles return undefined
Answered
Masai Lion posted this in #help-forum
Masai LionOP
I am trying to scope some styles as they are only used in this component.
Here is what I am doing…
journal/[slug]/page.jsx
src/styles/components/journalSingle.scss
Returned HTML
Not really sure what I am doing wrong?
Here is what I am doing…
journal/[slug]/page.jsx
import styles from '../../../src/styles/components/journalSingle.scss';
return (
<article class={`${styles.journalSingle} flow-l`}>
</article>
)src/styles/components/journalSingle.scss
.journalSingle {
padding-block-start: 8.75rem;
padding-block-end: 0rem;
@media screen and (min-width: 768px) {
padding-block-start: 14.875rem;
}
}Returned HTML
<article class="undefined flow-l"></article>Not really sure what I am doing wrong?
Answered by riský
[scss module](https://nextjs.org/docs/app/building-your-application/styling/sass) is the same concept as [normal css module](https://nextjs.org/docs/app/building-your-application/styling/css-modules) - ie doing what you want
16 Replies
https://nextjs.org/docs/app/building-your-application/styling/css-modules: only module.css can be imported directly to a style of a tag/component, normally when importing it just makes the values global for all in the page
Asian black bear
tl;dr rename
journalSingle.scss to journalSingle.module.scssalso in React it is customary to use the prop
className= instead of class=But the className part I am amazed that it worked (but yeah should fix)
Asian black bear
@riský I am not sure about the builtin support, but I have personally used CSS modules with SCSS, so it definitely exists.
Asian black bear
You can use component-level Sass via CSS Modules and thehttps://nextjs.org/docs/app/building-your-application/styling/sass.module.scssor.module.sassextension.
I didn't see it on the CSS module page, that's all, but nice to know 🙂
Asian black bear
I agree they really should mention it on the page about modules
Masai LionOP
Thanks for the responses. class not className is just a typo here but thanks for pointing out. So is there no way of scoping this little chunk of SCSS to the component?
Masai LionOP
Thanks again, the Next article doesn't explain what is actually happen here. Adding module to .scss just looks like a naming convention, but I suspect it does more. What does module actually do?
[scss module](https://nextjs.org/docs/app/building-your-application/styling/sass) is the same concept as [normal css module](https://nextjs.org/docs/app/building-your-application/styling/css-modules) - ie doing what you want
Answer
and it isn't just a naming convention because nextjs does things when it is there...
@Masai Lion Thanks again, the Next article doesn't explain what is actually happen here. Adding module to .scss just looks like a naming convention, but I suspect it does more. What does module actually do?
Asian black bear
It has a special rule in Webpack to tell the css/scss loader to treat it as a module file.
@Masai Lion just checking, do you understand how scss modules work/ is your original issue solved?