question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

css-loader + CSS modules pure selectors

See original GitHub issue

Bug report

Describe the bug

css-loader error on build.

To Reproduce

After migrating to 9.2 and testing the CSS modules features, the below configuration started erroring.

colors.css (containing only values)

@value customGreen: #3ba150;

Component.module.css

@value customGreen from "./colors.css";

.custom {
  color: customGreen;
}

I am having:

./Component.module.css (./node_modules/css-loader/dist/cjs.js??ref--5-oneOf-2-1!./node_modules/postcss-loader/src??__nextjs_postcss!./Component.module.css)
CssSyntaxError
Selector ":import("./colors.css")" is not pure (pure selectors must contain at least one local class or id)

Expected behavior

Well it did seem to work when I had

next.config.js

module.exports = withPlugins(
  [
    [
      withCSS,
      {
        cssLoaderOptions: {
          localIdentName: '[name]_[local]_[hash:6]',
        },
        cssModules: true,
      },
    ],
  ],
  nextConfig
);

Not sure if there’s some tweaking to do some where, not a champ on CSS modules stuff.

I’ve tried to understand this test but no luck.

System information

  • Version of Next.js: 9.2

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:28
  • Comments:25 (6 by maintainers)

github_iconTop GitHub Comments

53reactions
HoraceShmoracecommented, Mar 10, 2020

I solved my issues by moving away from implicit HTML calls (ex: nav and <nav> ) for specific elements, instead calling my components with classes (ex .nav and following up with <nav className={s.nav}>

I’ve been attempting to migrate our codebase onto Next, but just today discovered that our SCSS implementation breaks because all of our selectors have to be pure (and plenty are not). While I get why pure selectors would be ideal, it makes it impossible for large, enterprise projects full of “legacy” SCSS to migrate. I’ll never get funding for a tech debt effort to update 100+ scss files. There should be a flag to turn off pure mode.

38reactions
ematipicocommented, Apr 23, 2020

Same here. At present we can’t migrate to this built-in feature because of this problem.

Read more comments on GitHub >

github_iconTop Results From Across the Web

css-loader | webpack - JS.ORG
The loader replaces local selectors with unique identifiers. The chosen unique identifiers are exported by the module. :local(.className) { background: red ...
Read more >
Targeting Pure elements in next.js with CSS modules
You will need to use a global stylesheet to target pure elements as selectors. They cannot be component-scoped. Further, you can only import...
Read more >
How to configure CSS Modules for webpack - LogRocket Blog
This is achieved by creating a unique class name for CSS selectors, allowing you to use the same CSS class name in different...
Read more >
Basic Features: Built-in CSS Support - Next.js
Next.js supports including CSS files as Global CSS or CSS Modules, using `styled-jsx` for CSS-in-JS, or any other CSS-in-JS solution! Learn more here....
Read more >
client/node_modules/css-loader - GitLab
Then add the plugin to your webpack config. For example: file.js ... Using pure value requires selectors must contain at least one local...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found