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 Modules not pulling in localIdent name in prod builds

See original GitHub issue

node v10.14.1 macOs v10.14.3 extract-css-chunks-webpack-plugin v4.0.1 css-loader v2.1.1 webpack v4.29.6 terser-webpack-plugin v1.2.3

Starting off: I just upgraded and tried out in local dev mode and HMR works again!! This is huge in keeping parity between local dev and stage/production styles (and render ordering).

That said currently my prod builds are producing javascript where all of my import classes from './file.scss'; return <div className={classes.someClass} />; (roughly speaking of course) result in ‘undefined’ classes on the elements.

I’ve confirmed prod builds are exactly the same, except:

  1. The hot and reloadAll ExtractCssChunks.loader options are set to false in production
  2. The new ExctactCssChunks(); has different file names between builds
  3. Production builds obviously turn on optimization and minimization.

I can confirm that in prod the CSS file is built and included as expected, both dev and prod configurations use cacheGroups to generate a single css file, and dev users hot reloading/webpack-dev-server.

Swapping ExtractCssChunks with MiniCssExtract and leaving all set options, configuration, etc the same (literally just find-and-replace) fixes this issue in production builds.

My webpack configs can be found in this gist if it helps.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:3
  • Comments:29 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
dagda1commented, Apr 5, 2019

all good in the hood for ssr also. Great work sir. I’m now going to look at the diff between 4.2 and 4.3!

1reaction
ScriptedAlchemycommented, Mar 25, 2019

Haha! Only reason I maintain this, my hate for style loader. You don’t get an accurate reflection of production and style loader wrecks performance

Read more comments on GitHub >

github_iconTop Results From Across the Web

css module classes not there in production - Stack Overflow
ok I have everything working in as far as the classes are now on the object, e.g. FormInput now has a class FormInput__form-input___2PK4N...
Read more >
css-loader | webpack - JS.ORG
If set to false , css-loader will not parse any paths specified in url or image-set . ... Allows to redefine basic loader...
Read more >
Webpack with CSS Modules - E.Y.
“A CSS Module is a CSS file in which all class names and animation names are scoped locally by default.” So you can...
Read more >
css-loader - npm
Allows to redefine basic loader context for local ident name. webpack.config.js. module.exports = ...
Read more >
Customize CSS Loader options in Next.js - An Idiosyncratic Blog
Recently when working on a project migrating the code from Gatsby to ... Next.js supports CSS Modules using the [name].module.css file ...
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