Webpack return ValidationError: CSS Loader Invalid Options

Viewed 8057

I'm getting an error for css loader invalid option and my webpack.conifg.js code is as follows :

const path = require('path');
const HtmlWebPackPlugin = require("html-webpack-plugin");

const htmlWebpackPlugin = new HtmlWebPackPlugin({
    template: "./public/index.html"
});

module.exports = {
    entry: "./src/index.js",
    output: {
        path: path.resolve('dist'),
        filename: 'bundled.js'
    },
    module: {
        rules: [
            {
                test: /\.js$/,
                exclude: /node_modules/,
                use: {
                    loader: "babel-loader"
                }
            },
            {
                test: /\.css$/,
                use: [
                    {
                        loader: "style-loader"
                    },
                    {
                        loader: "css-loader",
                        options: {
                            modules: true,
                            importLoaders: 1,
                            localIdentName:"[name]_[local]_[hash:base64]",
                            sourceMap: true,
                            minimize: true
                        }
                    }
                ]
            },
            { 
                test: /\.(png|jpg|woff|woff2|eot|ttf|svg)$/,
                loader: 'url-loader?limit=100000' 
            }
        ]
    },
plugins: [htmlWebpackPlugin]
};

I don't know where I'm doing wrong.Please help me to solve this issue. I'm using webpack for reactjs 4 and webpack version is 4. Thanks

4 Answers

This is what resolved my case:

css-loader 2.1.1

{ loader: 'style-loader'},
{
  loader: 'css-loader',
  options: {
    modules: true,
    localIdentName: '[local]',
    import: true,
    importLoaders: true,
  }
},
{ loader: 'sass-loader'}                

css-loader 3.0.0

{ loader: 'style-loader'},
{
  loader: 'css-loader',
  options: {
    modules: {
      mode: 'local',
      localIdentName: '[local]',
    },
    import: true,
    importLoaders: true,
  }
},
{ loader: 'sass-loader'}                

Try commenting out:

// minimize: true

Commenting out minimize worked previously, though I began a new project with a fresh install of css-loader, and the culprit this time around is importLoader: 1. Just remove importLoader and it should work.

I'm using css modules with React, and everything is running properly.

This worked for my VUE Js project:

Browse to the /build/utils.js file and in the object of thecss-loader comment on the option that is marking you in the error. In my case I had to comment:

minimize: process.env.NODE_ENV === 'production',

Related