Next.js Discord

Discord Forum

How to install scss in next js ?

Answered
Scaly-naped Pigeon posted this in #help-forum
Open in Discord
Avatar
Scaly-naped PigeonOP
I have a question , how can I install scss into next js after installing npm i sass ?

I made an index.scss file and then I imported it inside _app.js and then I configured it like this in next.config.js but it doesn't work

const nextConfig = { sassOptions: { includePaths: [path.join(__dirname, 'styles')], additionalData: '@import "./index.scss";', }, }

am i doing something wrong ?
Inside index.scss I have this

@import url('./base.scss'); @import url('./globals.scss'); @import url('./header.scss'); @import url('./home.scss');

50 Replies

Avatar
show your _app
Avatar
Scaly-naped PigeonOP
Image
this is my _app but i always get error for importing index.scss , also if i removed it the index.scss never gets imported
Avatar
you arent using the scss anywhere
Avatar
Scaly-naped PigeonOP
I imported it inside next.config.js , also inside _app
Avatar
the docs clearly show you need to apply the css into the component
Avatar
Scaly-naped PigeonOP
can I just do index.scss and just import every scss file inside it and then import only the index.scss ? something like this
Image
Avatar
i am pretty sure you need to use a plugin to roll up the scss if you do that
i know you need to with other css types
Avatar
Try it
Avatar
Scaly-naped PigeonOP
yea I am trying, because keep importing scss files will be alot of work when it comes to a big app , wanted to do the simple ways ^^
I did but it didn't work , i am trying right now to find a way
Avatar
then use tailwind 😉
Avatar
Scaly-naped PigeonOP
yea I may use tailwind on some stuff , but I write faster css code than tailwind because I have 3 years on writing css and only 4 months on tailwind 🤣🤣
Avatar
You could import every file in _app.js
If the css import syntax doesn’t work.
Es 6 import
Avatar
i use postCSS with tailwind to rollup
but… dont know how that works with scss
Answer
Avatar
Just try something simple, import 1 file that imports another
Avatar
Scaly-naped PigeonOP
I always use css in all of my projects but in big project i use scss but its my first time using it with next js
will try that and tell you if it works
Avatar
Ok. I use PostCSS and PostCSS mixins.
Love it.
Avatar
glad that worked!
Avatar
All you need is PostCSS config
Avatar
… i… i know? 😆
did you mean to reply to op?
Avatar
No, you replied to me, so I also replied 🤣
Avatar
oh shit.
i did
Avatar
Scaly-naped PigeonOP
this is working , I changed scss files with _base.scss etc

@import 'base';
@import 'global';
@import 'header';
@import 'home';

this is working
Avatar
failure for cajun
Avatar
It’s like inception
Brilliant!
Avatar
Scaly-naped PigeonOP
renaming files with _ and then import it like above works fine ^^
Avatar
so postcss was the answer?
^ this is technically the answer then. just also mentions tailwind
Avatar
Scaly-naped PigeonOP
I really like the _ thing and then call it inside index.scss , this saves alot of imports in the future and it will give the ability to do light mode / dark mode more easily ^^
Avatar
The problem was the way the imports were done. The article I shared cleared that up I think.
Avatar
sounds good to me!
Avatar
Scaly-naped PigeonOP
this article should be posted on next js docs It covers the way , how people should imports scss into a single file
is there anyway to recommend this to next js team stuff ?
Avatar
I would open a PR and add some additional info perhaps in one of the docs pages for the SCSS setup.
Avatar
Scaly-naped PigeonOP
yup that would be very helpful for other users to know about this trick
Avatar
sounds like the headline of clickbait
JUST USE THIS ONE EASY TRICK FOR PERFECT SCSS