Tieme Tieme - 1 year ago 218
Sass (Sass) Question

Error when combining sass-loader with css-modules

I'm getting the following error when using SASS's


ERROR in ./src/special.scss
Module build failed: ModuleBuildError: Module build failed: Unknown word (11:14)

9 |
10 | @mixin mediaquery($name) {
> 11 | @media #{map-get($breakpoints, $name)} {
| ^
12 | @content;
13 | }
14 | }

This is only happening when I use both the
and another loader.

I first thought this was caused by the PostCSS Loader, but it seems like it's the sass-loading causing problems and not transforming the scss when using

I've created a sample repo illustrating the problem: https://github.com/tiemevanveen/sass-css-components-fail-example.

You can use the different branches to test:

Only the first and the last branch run without errors.

I've created the log-source example to see what the sass-loader is returning and it looks like it's not transforming the sass (but this might also be me misinterpreting how the loaders work).

The other example without css modules does show the right transformed code..

I'm puzzled why the master branch (without postcss or another custom loader) is working fine though.. if something would be wrong with the sass-loader then that one should also fail right?

I've filed an issue, but I'm thinking this has more chance on StackOverflow since it's such a specific problem and might be more a config problem. Here's my webpack config:

const webpack = require('webpack');
const path = require('path');
const autoprefixer = require('autoprefixer');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const WriteFilePlugin = require('write-file-webpack-plugin');

module.exports = {
devtool: 'source-source-map',
debug: true,
context: path.resolve(__dirname, './src'),
entry: {
app: './index.js'
output: {
path: path.resolve(__dirname, './static'),
filename: '[name].js',
publicPath: '/static/'
devServer: {
outputPath: path.resolve(__dirname, './static'),
plugins: [
new webpack.NoErrorsPlugin(),
new ExtractTextPlugin('[name].css'),
new WriteFilePlugin()
module: {
loaders: [
test: /\.scss$/,
loader: ExtractTextPlugin.extract('style-loader', [
// 'postcss-loader',
// + js loader
postcss: [
autoprefixer({ browsers: ['> 0.5%'] })
resolveLoader: {
fallback: [
path.resolve(__dirname, 'loaders'),
path.join(process.cwd(), 'node_modules')
resolve: {
extensions: ['', '.js', '.json'],

Answer Source

You need to increase the importLoaders query parameter as you add loaders. That feature is poorly documented and confusing, but in your samples repo, importLoaders=2 with both Sass and PostCSS works.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download