Next.js: Global scss variable

Created on 26 Mar 2020  Â·  6Comments  Â·  Source: vercel/next.js

Bug report

Sass variables in global file aren't visible in .module scss files.

To Reproduce

  1. clone - https://github.com/vitaliemiron/nextjs-global-scss
  2. npm i
  3. npm run dev
SassError: Undefined variable.
  â•·
3 │   color: $blue;

Screenshots

Screen Shot 2020-03-26 at 18 15 59

System information

  • Version of Next.js: 9.3.1

Most helpful comment

I'll recommend creating a common scss file includes all variables/functions/mixins, and also set up a webpack alias for that file. Then in the component sass files, you could @use "common" as *; and start using all your variables.

All 6 comments

I'll recommend creating a common scss file includes all variables/functions/mixins, and also set up a webpack alias for that file. Then in the component sass files, you could @use "common" as *; and start using all your variables.

But that means manually importing variables, mixins etc in every .module.scss files. Further, adding custom plugins like sass-resources-loader disables the built-in css configuration .

So I tried, switching back to [email protected] and using zeit@sass plugin with sass-resources-loader in next.config.js which solved the problem. Still hoping for a way in [email protected]

But that means manually importing variables, mixins etc in every .module.scss files. Further, adding custom plugins like sass-resources-loader disables the built-in css configuration .

So I tried, switching back to [email protected] and using zeit@sass plugin with sass-resources-loader in next.config.js which solved the problem. Still hoping for a way in [email protected]

This solution works in [email protected] for me.
But in this example they import styles without sass-resources-loader - https://github.com/zeit/next.js/tree/canary/examples/with-next-sass

My solution was to move to styled components.

This needs to be addressed. Using withSass() from @zeit/next-sass disables the Buil-in CSS support (https://err.sh/next.js/built-in-css-disabled)

Hello Team
I have facing issues regarding the next-CSS . I have using next-CSS but they are giving me a warning and when I removed the next-CSS from next.config file. my style CSS has not loaded chunks in the production. and my CSS is out of order in a production build.
Can you plz help me.

This is the expected behavior. Please import your variables as explained above.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

formula349 picture formula349  Â·  3Comments

knipferrc picture knipferrc  Â·  3Comments

ghost picture ghost  Â·  3Comments

rauchg picture rauchg  Â·  3Comments

olifante picture olifante  Â·  3Comments