mini-css-extract-plugin: Conflict order of styles
Good day, we moved from 2.6 webpack to 4.28.4. It’s a big bump and of course we migrated from old css plugin to new mini-css-extract-plugin. However, it doesn’t bundle css properly anymore, which causes wrong render We have dozens of the next warnings. Seems like something is wrong with optimization of chunks of css
WARNING in chunk bootstrap [mini-css-extract-plugin]
Conflicting order between:
* css ./node_modules/css-loader!./node_modules/sass-loader/lib/loader.js!./src/styles/components/1.scss
* css ./node_modules/css-loader!./node_modules/sass-loader/lib/loader.js!./src/styles/components/2.scss
* css ./node_modules/css-loader!./node_modules/sass-loader/lib/loader.js!./src/styles/components/3.scss
* css ./node_modules/css-loader!./node_modules/sass-loader/lib/loader.js!./src/styles/components/4.scss
rule is
{
test: /\.s?css$/,
use: [
MiniCssExtractPlugin.loader,
'css-loader',
'sass-loader'
]
}
optimization looks like
optimization: {
splitChunks: {
name: 'bootstrap',
minChunks: Infinity,
cacheGroups: {
bootstrap: {
filename: '[name].[chunkhash].js'
},
styles: {
name: 'styles',
test: /\.css$/,
chunks: 'all',
enforce: true
}
}
}
},
plugins is
new MiniCssExtractPlugin({ filename: 'style.css' })
if I replace MiniCssExtractPlugin.loader
with style-loader
, it seems to be switched off and error no longer appears, except I have no static/style.css
file generated and all styles become inlined
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 1
- Comments: 23 (3 by maintainers)
It is just warning you can ignore this
This is still an issue, why was it closed?
Okay, so you are proposing me to check the order of imports in components which use css modules separately. That’s interesting and can be confused for me. If you are really want mini-css-extract-plugin users to do that, so please create eslint plugin which will help us to do that, otherwise, mini-css-extract-plugin developers should fix this issue and make it as we had before.
Sorry, but the “check your order” suggestion is pretty much impossible in a larger application without a tool doing that and thus kind of useless.
i’m ignorning my CI is not.
It’s 2023 and we are still struggling with it. any update?
Because you have conflict in order, it is expected, you need fix order, extracting css sometimes is non deterministic
@vtereshyn As you can see, we have discussed this topic here. And having proper order makes sense. However, the old one
extract-text-webpack-plugin
was able to resolve this issue itself properly. I wondered, why new one cannot do the same. This is a deal breaker for me right now to move to webpack 4. I resolved all the other issues, but this one cannot be resolved as no other plugin is available to be compatible. And as many, we have hundreds of files in project to be shuffled properly to import as needed. But I tried to do it manually and failed, as I can’t comprehend proper file imports tree for such big amount of components already. And also I didn’t find a tool, which would help me to traverse this file tree. So literally I am stuck and have no solution to move on.For me
This seems to be an unfixable problem if you are using a component library and it’s imports aren’t consistent order.
For example, antd
@vtereshyn Check the order of the import of your components.
Example:
You have two components:
📄 Header.js
import css from './header.scss';
📄 Footer.js
import css from './footer.scss';
SCSS files:
📄 header.scss
@import 'variables';
📄 footer.scss
@import 'variables';
📄 variables.scss
You have two views/pages/containers:
📄 Page1.js
📄 Page2.js
Reordering Page2’s imports should solve your issues
@evilebottnawi coming back to this question. I found that
mini-css-extract-plugin
doesn’t include almost allscss
files I have in project. We talked about warnings regarding proper order. However, does it mean, that if warning appears, than styles will not be included? If not, help me find out why styles are not included. Here is my configany updates?
@evilebottnawi this is not just a warning. In projects where people have same class names, overrides of styles, etc like that (sometimes it happen without our will) it makes styles broken and we can’t move to this solution
For me, the same warnings are coming and the worst part is no css is applied on the project. FYI: I have used purify css too.