Skip to content

CssModule context property is null in v0.8.1 #473

Closed
@i-like-robots

Description

@i-like-robots
  • 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions