Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Webpack sass-loader Invalid CSS

I get this error whenever running my build.

Invalid CSS after "module.exports": expected "{", was '= "data:text/x-scss'

I've also tried using a vanilla JS webpack config and get the same error, so it's not the TypeScript config. Also tried extract-text-webpack-plugin but get the same error. The actual app is working fine, but obviously has no CSS. Here is the config.

import * as path from 'path';
import * as webpack from 'webpack'

const config: webpack.Configuration = {
    entry: {
        app: ['./js/main.ts']
    },
    output: {
        path: path.resolve(__dirname, './dist/js'),
        filename: '[name].js'
    },
    module: {
        rules:[
            {
                test: /\.html$/,
                loader: 'ngtemplate-loader?prefix=/&module=app&relativeTo=' + (path.resolve(__dirname, './js/app')) + '/!html-loader'
            },
            {
                test: /\.ts$/,
                loader: 'awesome-typescript-loader'
            },
            {
                test: /\.(sass|scss|ttf|svg|woff)$/,
                use: [{
                    loader: "style-loader"
                }, {
                    loader: "css-loader"
                }, {
                    loader: "sass-loader",
                }, {
                    loader: "url-loader"
                }]
            }
        ]
    }
}

export default config

And here is the snippet of the main sass file.

@import "utilities/variables";
@import "utilities/animations";
@import "utilities/helpers";

Which is imported in the main app file with:

import '../sass/sass.scss';
like image 962
Ian Hoar Avatar asked Jan 03 '23 11:01

Ian Hoar


1 Answers

I think the error is because you use url-loader for Sass files somehow. Split your webpack.config rule for (sass|scss|ttf|svg|woff) so it looks like this:

{
  test: /\.(ttf|svg|woff)$/,
  use: [{
    loader: "url-loader"
  }]
},
{
  test: /\.(sass|scss)$/,
  use: [{
    loader: "style-loader"
  }, {
    loader: "css-loader"
  }, {
    loader: "sass-loader",
  }]
}
like image 149
GProst Avatar answered Jan 14 '23 13:01

GProst