Search code examples
webpack-4bourbonmini-css-extract-plugin

webpack4 mini-css-extract-plugin with bourbon


I have my scss file which imports a scss file which further imports bourbon and bourbon-neat. I even searched various issues on the forum but did not find the issue where in the scsss to css conversion, the case is to include bourbon.

webpack 4.28.1 mini-css-extract-plugin 0.5.0

I am seeing the following error:

Child mini-css-extract-plugin node_modules/css-loader/dist/cjs.js!node_modules/sass-loader/lib/loader.js??ref--5-2!src/component/styles/main.scss:enter code here
Entrypoint mini-css-extract-plugin = *
[./node_modules/css-loader/dist/cjs.js!./node_modules/sass-loader/lib/loader.js?!./src/component/styles/main.scss] ./node_modules/css-loader/dist/cjs.js!./node_modules/sass-loader/lib/loader.js??ref--5-2!./src/component/styles/main.scss 373 bytes {mini-css-extract-plugin} [built] [failed] [1 error]

ERROR in ./src/component/styles/main.scss (./node_modules/css-loader/dist/cjs.js!./node_modules/sass-loader/lib/loader.js??ref--5-2!./src/component/styles/main.scss)
Module build failed (from ./node_modules/sass-loader/lib/loader.js):

var path = require('path');
^
      Invalid CSS after "v": expected 1 selector or at-rule, was "var path = require("
      in /Users/../node_modules/bourbon/index.js (line 1, column 1)

My webpack.config.js file is here

const path = require('path');
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const OptimizeCSSAssetsPlugin = require("optimize-css-assets-webpack-plugin");
module.exports = {
    entry: {
        "app": ['whatwg-fetch',"./src/component/index.ts", "./src/component/styles/main.scss"],
        "app-helper": "./src/component/helpers.ts"
    },
    output: {
        path: path.resolve(__dirname, './src/component/dist'),
        filename: "[name].bundle.js"
    },
    module: {
        rules: [
            {
                test: /\.tsx?$/,
                use: 'ts-loader',
                exclude: /node_modules/
            },
            test: /\.(sa|sc|c)ss$/,
            use: [
                MiniCssExtractPlugin.loader,
                'css-loader',
                {
                    loader: "sass-loader",// compiles Sass to CSS
                    options: {
                        includePaths: [
                            'node_modules/bourbon/app/assets/stylesheets',
                            'node_modules/bourbon-neat/app/assets/stylesheets'
                        ]
                    }
                }
            ],
        ]
    },
    plugins: [
        new MiniCssExtractPlugin({
            filename: './src/component/dist/output-style.css',
        })
    ],
    optimization: {
        minimizer:[
            new UglifyJSPlugin({
                cache: true,
                parallel: true,
                sourceMap: true // set to true if you want JS source maps
            }),
            new OptimizeCSSAssetsPlugin({})
        ]
    }
}

Please provide your valuable suggestions.


Solution

  • This turns out to be an issue with sass-loader version 7.x . I changed sass-loader dependency back to 6.0.7 and it started working like charm. Here is the stackoverflow thread which helped

    Angular 2 Node Bourbon Error