Skip to content

CssModule context property is null in v0.8.1 #473

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

Closed
i-like-robots opened this issue Dec 17, 2019 · 5 comments · Fixed by #474
Closed

CssModule context property is null in v0.8.1 #473

i-like-robots opened this issue Dec 17, 2019 · 5 comments · Fixed by #474

Comments

@i-like-robots
Copy link

i-like-robots commented Dec 17, 2019

  • Operating System: Mac OS 10.14
  • Node Version: 10.14
  • NPM Version: 6.4.1
  • webpack Version: 4.41.2
  • mini-css-extract-plugin Version: 0.8.1

Expected Behavior

We have implemented code splitting in our apps which uses each module's context property to decide whether they should be extracted into separate chunk. We have used this configuration for some time but has broken when using v0.8.1 of this package.

Actual Behavior

The context property for instances of CssModule is null instead of a string as we expect so our Webpack compilation fails. e.g.:

(module) => module.context.includes('foo') // TypeError: Cannot read property 'includes' of null

Code

Here is an example configuration for enabling code splitting using module.context:

// webpack.config.js
module.exports = {
  optimization: {
    splitChunks: {
      cacheGroups: {
        vendors: {
          test (module) {
            return module.context.includes('dom-loaded')
          }
        }
      }
    }
  }
}

How Do We Reproduce?

Try adding the code splitting configuration shown above to a project using this plugin and a CSS entry point (or try any configuration which expects module.context to be a string).

EDIT: test repo here https://github.com/i-like-robots/broken-css-extract-plugin

@i-like-robots i-like-robots changed the title CssModule missing context property in v0.8.1 CssModule context property is null in v0.8.1 Dec 17, 2019
@alexander-akait
Copy link
Member

alexander-akait commented Dec 17, 2019

We don't touch this code in 0.8.1, please create reproducible test repo

@i-like-robots
Copy link
Author

i-like-robots commented Dec 17, 2019

Here you go: https://github.com/i-like-robots/broken-css-extract-plugin

If you run npx webpack or npm run build it should fail.

Install v0.8.0 of this plugin (npm i [email protected]) and run the Webpack build again and it should pass.

Hope that helps!

@alexander-akait
Copy link
Member

@i-like-robots what about return module.context && module.context.includes('dom-loaded')?

@i-like-robots
Copy link
Author

i-like-robots commented Dec 17, 2019

We can do that but I'm concerned that a public part of this module's interface has changed unexpectedly. I assume this may cause other users a problem as well 😱

@i-like-robots
Copy link
Author

Thank you @evilebottnawi - much appreciated 🙇

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants