Vue-loader: Webpack log a Err about "Module not found: Error: Can't resolve 'scss-loader'" when I use "<style lang="scss" scoped>" in .vue file

Created on 20 Mar 2017  路  2Comments  路  Source: vuejs/vue-loader

when I use

<style lang="scss" scoped>
@import '../scss/variables.scss';

main {
  color: $red;
}
</style>

in .vue file, and compile it with vue-loader. What's more, I want to extract the css as a separate file. So I config the webpack like this:

const ExtractTextPlugin = require('extract-text-webpack-plugin');
const extractSass = new ExtractTextPlugin({
    filename: '[name].[hash].css'
});
const config = {
    //...

    module: {
        rules: [
             {
                test: /\.vue$/,
                use: [
                    {
                        loader: 'vue-loader',
                        options: {
                            loader: {
                                css: extractSass.extract({
                                    use: [
                                        {
                                            loader: 'css-loader',
                                            options: {
                                                sourceMap: true
                                            }
                                        }, {
                                            loader: 'sass-loader',
                                            options: {
                                                sourceMap: true
                                            }
                                        }
                                    ],
                                    fallback: 'vue-style-loader'
                                })
                            }
                        }
                    }
                ],
                include: [srcPath]
            },
            //...
        ]
    },

    plugins: [
        extractSass,
        //...
    ]
};

module.exports = config;

when I webpack it, it comes out a error:

Module not found: Error: Can't resolve 'scss-loader' in '...'

Could you help me with that? thx.

Most helpful comment

@qidaneix actually now that I look closer - this isn't about unit testing at all!

You can take a look at the webpack template for an example of how to get scss working:
https://github.com/vuejs-templates/webpack-simple/blob/master/template/webpack.config.js

I'd recommend using the webpack or webpack simple templates as a starting point. For your vue projects / experiments.

All 2 comments

Same as the previous issue I raised #724

@qidaneix actually now that I look closer - this isn't about unit testing at all!

You can take a look at the webpack template for an example of how to get scss working:
https://github.com/vuejs-templates/webpack-simple/blob/master/template/webpack.config.js

I'd recommend using the webpack or webpack simple templates as a starting point. For your vue projects / experiments.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

yozman picture yozman  路  4Comments

lijialiang picture lijialiang  路  3Comments

birdgg picture birdgg  路  3Comments

Makio64 picture Makio64  路  4Comments

fuyan-run picture fuyan-run  路  3Comments