-
Notifications
You must be signed in to change notification settings - Fork 27.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CssSyntax error: Selector "&:hover" is not pure (pure selectors must contain at least one local class or id) #10475
Comments
As far as I know, you cannot nest like that in CSS modules. This example from the css modules docs shows an example in which they are using |
@andrasna
|
Exactly as per #10475 (comment) |
@timneutkens just checking, but the Next docs say it supports postcss, and I'm using postcss exclusively to get nested support (as css does everything else I need), but in the particular combination of Next + Postcss + Nesting + CSS Modules - does this mean nested CSS (via postcss) isn't supported/doesn't work? |
it didn't work for me. |
Hi, https://github.com/andrasna/hello-next-css-module-issue I have unarchived and updated the repository with the issue, where I think the above code is a solution. |
I have nested selectors working with css modules with storybook, but as soon as I run it through next.js it fails, which makes me think this issue was closed incorrectly. To be fair, I had to finesse it so that the css rules applied to sass as well, but still it works. Wondering why I can't get it to work in Next.js. If it helps, here is my storybook config that works: module.exports = {
stories: [
// Paths to the story files
'../stories/**/*.stories.mdx',
'../stories/**/*.stories.@(js|jsx|ts|tsx)'
],
addons: [
'@storybook/addon-links',
'@storybook/addon-essentials',
{
name: '@storybook/addon-postcss',
options: {
postcssLoaderOptions: {
implementation: require('postcss')
}
}
},
{
name: '@storybook/preset-scss',
options: {
cssLoaderOptions: {
modules: true,
}
}
},
],
webpackFinal: async (config) => {
// Default rule for images /\.(svg|ico|jpg|jpeg|png|gif|eot|otf|webp|ttf|woff|woff2|cur|ani|pdf)(\?.*)?$/
const fileLoaderRule = config.module.rules.find(rule => rule.test && rule.test.test('.svg'));
fileLoaderRule.exclude = /\.svg$/;
config.module.rules.push({
test: /\.svg$/,
enforce: 'pre',
use: ['@svgr/webpack'],
});
const cssRule = config.module.rules.find(rule => rule.test && rule.test.test('.css'));
const sassRule = config.module.rules.find(rule => rule.test && rule.test.test('.scss'));
const postCSSLoader = cssRule.use.find(config => config.loader && config.loader.indexOf('postcss-loader') > 0);
sassRule.use.push(postCSSLoader);
return config;
},
}; |
Same issue here, im using > 1 | %IndeterminateMixin {
| ^
2 | content: '';
3 | position: absolute;
wait - compiling...
error - ./node_modules/react-components/progress/progress.module.css:1:1
Syntax error: Selector "%IndeterminateMixin" is not pure (pure selectors must contain at least one local class or id) |
This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
today ~83% of all browsers support css nesting: https://caniuse.com/css-nesting  https://caniuse.com/css-nesting https://developer.mozilla.org/en-US/docs/Web/CSS/Nesting_selector therefore this pr upgrades postcss-modules-local-by-default which fixes a bug in css-modules/postcss-modules-local-by-default#64) - `.foo { &:hover { a_value: some-value; } }` is pure - `.foo { html &:hover { a_value: some-value; } }` is pure - `.foo { &:global(.bar) { a_value: some-value; } }` is pure - `:global(.foo) { &:hover { a_value: some-value; } }` is **not** pure upgrading the package will allow using css nestings with or **without** postcss compilation it fixes the following error: ``` CssSyntaxError: postcss-modules-local-by-default: <css input>:1:8: Selector "&:hover" is not pure (pure selectors must contain at least one local class or id) ``` Fixes #55053 Fixes #33734 Fixes #10475 Co-authored-by: Sam Ko <sam@vercel.com>
The error
./pages/index.module.css (./node_modules/css-loader/dist/cjs.js??ref--5-oneOf-2-1!./node_modules/postcss-loader/src??__nextjs_postcss!./pages/index.module.css)
CssSyntax error: Selector "&:hover" is not pure (pure selectors must contain at least one local class or id) (4:3)
To Reproduce
https://github.com/andrasna/hello-next-css-module-issue
The above repository is based on following the examples in the documentation:
https://nextjs.org/docs/basic-features/built-in-css-support#adding-component-level-css
Expected behavior
As far as I understand, the above selector does contain a "pure selector", so it should work. However, apparently, since hover is nested in this example, it isn't recognized as a "pure selector".
The text was updated successfully, but these errors were encountered: