Non-module component styling #14672
Replies: 9 comments 17 replies
-
Unfortunately currently there is no way to do this. A primary reason would be that Next would not know what order to combine your individual stylesheets in, leading to unexpected results. |
Beta Was this translation helpful? Give feedback.
-
This is such a huge problem. Also, even if you use module to import your component style, it is such a pain to update those style from parent for different use cases. For example, if you just want to modify style of a button in About Page specifically, you would generally want to do something like this -
But if you use modules, it is hard to reference .c-Button from inside .p-About without using :global which gets messier by the second. Now that my rant is over, I would also genuinely appreciate viable solutions to this. |
Beta Was this translation helpful? Give feedback.
-
I'm sure this will be a big help for those of you who are migrating over from CRA. This is if you'd like to use normal string classes eg. className='example' I'm also able to import my global styles into my component level stylesheets, you can checkout my repo (install my packages for webpack and sass packages and checkout my next.config.js) https://github.com/Kirsten1996/nextjs-component-level-styling |
Beta Was this translation helpful? Give feedback.
-
Any solution - old Proj has all files in scss/sass and while upgrading to next js 11, it requires modules styles, migrating each and every file for a large scale project is being difficult What can be done in this case? |
Beta Was this translation helpful? Give feedback.
-
I ended up working around this terrible decision by fixing the webpack config:
|
Beta Was this translation helpful? Give feedback.
-
The latest method to disable css-module in Next.js is as following: Edit next.config.js: webpack(config) {
// disable css-module in Next.js
// source: https://github.com/vercel/next.js/discussions/14672#discussioncomment-4027237
config.module.rules.forEach((rule) => {
const { oneOf } = rule;
if (oneOf) {
oneOf.forEach((one) => {
if (!`${one.issuer?.and}`.includes('_app')) return;
one.issuer.and = [path.resolve(__dirname)];
});
}
})
return config;
}, Verified in next.js version: v12.3~v13.x See example: No CSS modules in next.js app: (json5 app) |
Beta Was this translation helpful? Give feedback.
-
Hey, is there any way to disable css modules in NextJs 13? |
Beta Was this translation helpful? Give feedback.
-
This is indeed an issue when migrating to Next from a codebase that accepts component level styles such as Remix (my use case). The solution above works for me, however TypeScript complains: Just in case it helps anyone, I also have to explicitly call the imported style in the main component export, even just simply like so: import styles from "./some-comp.scss";
export default function SomeComp() {
styles; /* loads styles */
return(
...
)
} |
Beta Was this translation helpful? Give feedback.
-
Any updates surrounding this? |
Beta Was this translation helpful? Give feedback.
-
Hi, I am new to Next.js and I am having some issues on component level styling.
So I have this component called
Card.js
with styleCard.scss
.📦 ./component/Card/Card.js
🎨 ./component/Card/Card.scss
If I use the module approach, everything works fine.
However, If I don't use
*.module.scss
, I am getting this error message.My question is, is there a way for us to import styles not as a module to a component? Thank you.
Beta Was this translation helpful? Give feedback.
All reactions