mini-css-extract-plugin: Webpack 5 - TypeError: The 'compilation' argument must be an instance of Compilation
- Operating System: OSX Catalina 10.15.6
- Node Version: 14.11.0
- NPM Version: 6.14.8
- webpack Version: 5.1.3
- mini-css-extract-plugin Version: 1.1.1
Expected Behavior
- No Errors when including
.scssfiles .scssfiles are transformed to css and output in dist directory
Actual Behavior
- Using
MiniCssExtractPlugin.loaderresults in webpack errors for every.scssfile:
“TypeError: The ‘compilation’ argument must be an instance of Compilation”

- Replacing
MiniCssExtractPlugin.loaderwith'style-loader'yields no errors and styles the application as intended, but css is not extracted (obviously). This leads me to suspect the issue has something to do with this plugin 🤔
Code
Versions:
"css-loader": "5.0.0",
"html-webpack-plugin": "5.0.0-alpha.6",
"mini-css-extract-plugin": "1.1.1",
"sass-loader": "10.0.3",
"style-loader": "2.0.0",
"webpack": "5.1.3",
"webpack-cli": "4.1.0",
Results in errors:
// weback config
plugins: [
// ...
new MiniCssExtractPlugin({
filename: '[name].[contenthash].css',
chunkFilename: '[id].css',
}),
],
module: {
rules: [
{
test: /\.(s)?css$/i,
use: [MiniCssExtractPlugin.loader, 'css-loader', 'sass-loader'],
},
// ...
]
}
No errors, no extract:
// webpack config
module: {
rules: [
{
test: /\.(s)?css$/i,
use: ['style-loader', 'css-loader', 'sass-loader'],
},
// ...
]
}
Is there anything obvious from this configuration that could yield errors with the compilation argument? Has anybody seen this before? I’m working on creating a small repo to reproduce the issue, but if you see a stupid mistake in here or have clarifying questions for me, please ask right away!
Thanks very much for your help! 👍
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 28 (14 by maintainers)
Looks like MiniExtractCssPlugin works fine as long as I don’t
npm linkto my library. I’ve gotsymlinks: falsein theresolvesection of my webpack config, but it still misbehaves.I’ve worked around this issue for now by changing my webpack config to use
style-loaderin development and MiniCssExtractPlugin in production.To clarify: MiniCssExtractPlugin works in both development and production modes as long as I don’t
npm linkto the library that lists MiniCssExtractPlugin as a dependency. If I runnpm installand then start the app without linking, it works great. If younpm link, you get the compilation TypeErrors@Christian24 found solution, how we can solve it, so just wait the next patch release
Some of the approaches will work, hard to say what is better, because it depends what you need, many developers uses
--hoistand it is good for them, but not in your case (as you say).Yes too, you can create helper function like
createWebpackConfigand export it frompackages/configWill work
Because some plugins require
Compilationinstance, some of them notYep, let’s do it and I will look at this