Languages

WebPack - WARNING in chunk ... [mini-css-extract-plugin] Conflicting order. Following module has been added:

8 points
Asked by:
Vanessa-Drake
718

I have decided to configure Webpack to extract/split my CSS files into separated files and multiple chunks - like JS files are. I need it for SSR in my React project.

It looks like CSS extracting/splitting can be made by mini-css-extract-plugin package.

But, there is some warning related to styles order. I noticed that the problem occurs when I use multiple dynamic imports to modules that both use indirectly the same styles inside.

I use import style from './style.scss' to attach styles to components.

Is there some way to order styles in the correct way?

Webpack error:

WARNING in chunk frontend_src_components_Editor_index_tsx-frontend_src_components_Editor-60b40a [mini-css-extract-plugin]                                                 
Conflicting order. Following module has been added:
 * css ./node_modules/css-loader/dist/cjs.js??ruleSet[1].rules[2].use[1]!./node_modules/sass-loader/dist/cjs.js!./frontend/src/components/Editor/style.scss
despite it was not able to fulfill desired ordering with these modules:
 * css ./node_modules/css-loader/dist/cjs.js??ruleSet[1].rules[2].use[1]!./node_modules/sass-loader/dist/cjs.js!./frontend/src/components/Editor/Tools/style.scss
   - couldn't fulfill desired order of chunk group(s) site-writer
   - while fulfilling desired order of chunk group(s) site-reader
 * css ./node_modules/css-loader/dist/cjs.js??ruleSet[1].rules[2].use[1]!./node_modules/sass-loader/dist/cjs.js!./frontend/src/components/Editor/Path/style.scss
   - couldn't fulfill desired order of chunk group(s) site-writer
   - while fulfilling desired order of chunk group(s) site-reader

 

Resources

  1. https://webpack.js.org/plugins/mini-css-extract-plugin/
  2. https://www.npmjs.com/package/mini-css-extract-plugin
  3. https://github.com/webpack-contrib/mini-css-extract-plugin
1 answer
6 points
Answered by:
Vanessa-Drake
718

The problem you try to solve is complicated.

There are available few solutions:

  1. re-organize styles imports order - it may not solve the problem,
  2. style each component locally and disable warnings by ignoreOrder: true property,
    e.g. webpack.config.js file:
    // ...
    
    module.exports = {
      plugins: [
        // ...
        new MiniCssExtractPlugin({
            filename: "[name].[chunkhash:5].css",
            chunkFilename: "[name].chunk.[chunkhash:5].css",
            ignoreOrder: true
        }),
        // ...
      ],
      // ...
    };
  3. do not use dynamic imports or lazy loading for React components - I know it opposite of what you need.

 

BTW: by styling components locally I mean to use unique className props with elements in components to prevent styles overriding.

0 comments Add comment
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join