I have a project on Vue.js and I plan to use CSS modules for my local styles (for sass and scss), but I keep on getting a 'Failed to compile error' on the CSS Loader validation part.
I already tried a lot of solutions on Github by configuring my Webpack in a lot of ways, but I keep on getting the same error.
Here's my webpack.config.js file under module.rules:
{
test: /\.scss$/,
use: [
'vue-style-loader',
{
loader: "css-loader",
options: {
modules: {
localIdentName: 'MyApp__[local]--[hash:base64:5]',
},
}
},
'sass-loader'
],
},
{
test: /\.sass$/,
use: [
'vue-style-loader',
{
loader: "css-loader",
options: {
modules: {
localIdentName: 'MyApp__[local]--[hash:base64:5]',
}
}
},
'sass-loader?indentedSyntax'
],
},
And this is how I use CSS modules on a child component in Vue:
<style lang="scss" module>
.subtitle{
font-size: 1rem !important;
}
.box{
padding: 20% 0 !important;
box-shadow: 0 2px 2px 0 rgba(0,0,0,0.14), 0 3px 1px -2px rgba(0,0,0,0.12), 0 1px 5px 0 rgba(0,0,0,0.20);
}
</style>
Here's the complete error that I'm getting:
ERROR in ./node_modules/css-loader/dist/cjs.js?{"localIdentName":"[hash:base64]_0","importLoaders":true,"modules":true}!./node_modules/vue-loader/lib/style-compiler?{"vue":true,"id":"data-v-68c39e04","scoped":false,"hasInlineConfig":false}!./node_modules/sass-loader/lib/loader.js!./node_modules/vue-loader/lib/selector.js?type=styles&index=0!
Module build failed: ValidationError: Invalid options object. CSS Loader has been initialised using an options object that does not match the API schema.
- options has an unknown property 'localIdentName'. These properties are valid:
object { url?, import?, modules?, sourceMap?, importLoaders?, localsConvention?, onlyLocals? }
at validate
I hope I could resolve this error.