I'm trying to extract the Webpack styles into a .css file using the mini-css-extract-plugin
. I'm getting an error stating that it cannot find the module.
ERROR in ./Common/Login/login.min.css Module build failed (from ./node_modules/mini-css-extract-plugin/dist/loader.js):
Error: Cannot find module '../../node_modules/css-loader/dist/runtime/api.js' at webpackMissingModule (C:@Code\node_modules\css-loader\dist\cjs.js!C:@Code\Common\Login\login.min.css:108:92)
It seems like the module location is a relative path ../../node_modules
that appears to be wrong if it is trying navigate from node_modules/css-loader/dist/cjs.js
. It seems like it should be ../../../
.
I have no idea where or why those relative paths are like that or if that is even the problem. Here is the relevant Webpack configuration options:
partialConfig = : webpack.Configuration = {
mode: "development",
entry,
resolve: {
modules: [
"node_modules",
path.resolve(__dirname),
],
extensions: [".ts", ".js", ".css"]
},
module: {
rules: [
{
test: /\.(bmp|gif|jpe?g|png|svg)$/,
exclude: /node_modules/,
use: "file-loader?name=images/[name].[ext]"
},
{
test: /\.(eot|ttf|woff|woff2)$/,
exclude: /node_modules/,
use: "file-loader?name=fonts/[name].[ext]"
},
{
test: /\.css$/,
exclude: /node_modules/,
use: [MiniCssExtractPlugin.loader, 'css-loader']
}
]
},
plugins: [
new MiniCssExtractPlugin({
filename: "[name]"
})
],
}
Any idea why the mini-css-extract-plugin
is bombing out like this? If I just use the style-loader
, then everything compiles correctly, but obviously the output is JavaScript instead of a cacheable CSS stylesheet file.