1

So I was trying to use Bulma and got a can't import _varibales.sass, which I have in my src folder. So I thought it was because I didn't configure webpack to support Sass.

So I followed the configuration instructions from this tutorial, but then I got a loader error. This is my first time using raw webpack as opposed to CRA. I did this because I wanted to understand Webpack and Babel more.

Another thing I have tried is the Webpack configuration found on the dart-sass configuration.

My error right now is:

[webpack-cli] Invalid configuration object. Webpack has been initialized using a configuration object that does not match the API schema.

configuration.module.rules[2] should be one of these: ["..." | object { compiler?, dependency?, descriptionData?, enforce?, exclude?, generator?, include?, issuer?, issuerLayer?, layer?, loader?, mimetype?, oneOf?, options?, parser?, realResource?, resolve?, resource?, resourceFragment?, resourceQuery?, rules?, sideEffects?, test?, type?, use? }, ...]

-> A rule. Details: * configuration.module.rules[2].loader should be a non-empty string.

And my webpack.config.js looks like this:

const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const Dotenv = require('dotenv-webpack');
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const isDevelopment = process.env.NODE_ENV === 'development'

module.exports = {
  mode: 'development',
  entry: path.resolve(__dirname, 'src', 'index.js'),
  output: {
    path: path.resolve(__dirname, 'dist'),
    filename: 'bundle.js',
    publicPath: '/'
  },
  module: {
    rules: [
      {
        test: /\.jsx?$/,
        exclude: /node_modules/,
        loader: 'babel-loader',
        options: {
          presets: ["@babel/preset-env", "@babel/preset-react"]
        }
      },
      {
        test: /\.module\.s(a|c)ss$/,
        loader: [
          isDevelopment ? 'style-loader' : MiniCssExtractPlugin.loader,
          {
            loader: 'css-loader',
            options: {
              modules: true,
              sourceMap: isDevelopment
            }
          },
          {
            loader: 'sass-loader',
            options: {
              sourceMap: isDevelopment
            }
          }
        ]
      },
      {
        test: /\.s(a|c)ss$/,
        exclude: /\.module.(s(a|c)ss)$/,
        loader: [
          isDevelopment ? 'style-loader' : MiniCssExtractPlugin.loader,
          'css-loader',
          {
            loader: 'sass-loader',
            options: {
              sourceMap: isDevelopment
            }
          }
        ]
      }
    ]
  },
  devServer: {
    historyApiFallback: true,
  },
  plugins: [
    new HtmlWebpackPlugin({ template: path.resolve(__dirname, 'src', 'index.html') }),
    new Dotenv(),
    new MiniCssExtractPlugin({
      filename: isDevelopment ? '[name.css]' : '[name].[hash].css',
      chunkFilename: isDevelopment ? '[id].css' : '[id].[hash].css'
    })
  ],
  resolve: {
    extensions: [".js", ".jsx", ".sass", ".scss"]
  }
};
4
  • What is your WebPack version? Commented Jan 10, 2021 at 19:46
  • According to my package.json, 5.12.2 Commented Jan 10, 2021 at 19:48
  • I guessed it would be 5 or later. Try to downgrade to a lower version, for example "webpack": "^4.41.5". These tutorials were likely written on top of the earlier version of WebPack and I doubt such compatibility would be issued. I struggled to work with version 5 or later so I eventually gave up and used the already mentioned version. Commented Jan 10, 2021 at 20:08
  • 1
    Alright thanks. It seems that was the issue. Commented Jan 10, 2021 at 20:40

2 Answers 2

1

You use WebPack version 5+. Downgrade to a lower version of WebPack to assure compatibility.

"webpack": "^4.41.5"

In case you need to stick with the 5+ version or to learn more about the error in the webpack.config.json configuration file, refer to Webpack v4 to v5 migration.

Sign up to request clarification or add additional context in comments.

Comments

0

Actuall, I had the same issue which draw me back to this question and I found the answer here (downgrading was not working as too many dependencies...) : https://webpack.js.org/loaders/sass-loader/

Instead of loader, it's 'use' that need to be used, like:

{ 
   test: /\.s(a|c)ss$/,
   use: ['style-loader','css-loader', 'sass-loader'
},

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.