Built-in Sass support not working. "Syntax error: Selector "body" is not pure" and other bullshit about non-pure selectors #16050
-
Bug reportI followed this explanation: https://nextjs.org/docs/basic-features/built-in-css-support Tried to use built-in scss support but now I am getting the "Syntax error: Selector "body" is not pure" error when trying to compile a .module.scss file using built-in sass support. Describe the bugIt happens when using pure css selectors like "body", "footer", "button" etc. (Also what the heck does "non-pure selector" even mean?? They seem pretty pure to me) Though scss works fine if I am using class selectors instead of tag selectors. To Reproduce
Expected behaviorIt should not fire these errors and compile to css without problems, because its just a simple selector. System information
Additional contextTried to reinstall: Next, node and sass. Doesn't work. |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 7 replies
-
The pure thing is about it being a css-module, which is not meant to be applied globally, but scoped to specific components. You can leave the "module" part out (so, "style.scss") and import it your _app.js |
Beta Was this translation helpful? Give feedback.
-
By design, CSS modules are scoped CSS classes and you'll need to import them within a JS file and apply them to an HTML element’s Example.module.scss .exampleClassName {
font-size: 12px;
} Example.js import { exampleClassName } from "./Example.module.scss";
const Example = () =>
<div className={exampleClassName}>
Scoped example
</div>;
export default Example; Selectors like Imagine you have 2 components that both alter the If you wish to use global selectors, then you should use a global stylesheet. Please refer to the css-modules documentation for more information. |
Beta Was this translation helpful? Give feedback.
-
As @stfnsr rightly said, it's not meant to be applied globally. So you can simply apply your styles in your global.css file for Next.js version 11.1.0. |
Beta Was this translation helpful? Give feedback.
-
Why is this even being validated? In my case in global.css we don't need html, body to be full height, ONLY for login page, wich is a module login.module.css. |
Beta Was this translation helpful? Give feedback.
-
Is there not a way to ignore this rule at all? We have multiple outlets being used with a shared library that does exactly this, and it's blocking me from using that library in a next app. There's not an ability to change it as prescribed, I just want to allow it. |
Beta Was this translation helpful? Give feedback.
By design, CSS modules are scoped CSS classes and you'll need to import them within a JS file and apply them to an HTML element’s
className
.Example.module.scss
Example.js
Selectors like
html
,body
,button
, etc are global (unscoped) selectors; in addition they also are not valid scoped classes (like how.exampleClassName
is scoped to adiv
element in the example above). Next expects CSS modules to be pure in that they don’t produce side effects (like altering thebody
style base…