Search code examples
angularjswebpackwebpack-dev-serverwebpack-2webpack-3

Webpack 3: Why do I get :You may need an appropriate loader to handle this file type.?


I am trying to create a webpack build for my angularjs app. I keep getting:

ERROR in ./client/app/app.scss
Module parse failed: Unexpected character '@' (1:0)
You may need an appropriate loader to handle this file type.
| @import "common/common";
| 
| .app {
 @ ./client/app/app.scss 4:14-37
 @ ./client/app/app.component.js
 @ ./client/app/app.js
 @ multi (webpack)-dev-server/client?http://localhost:9000 ./client/app/app.js

This type of error is repeated a few times...

I am trying to use the DLLreference plugin this is my app. config:

var path = require("path");
var webpack = require("webpack");

module.exports = {
  devServer: {
    contentBase: path.join(__dirname, "build"),
    compress: true,
    port: 9000
  },
  node: {
    fs: 'empty'
  },
  cache: true,
  devtool: "eval", //or cheap-module-eval-source-map
  entry: {
    app: path.join(__dirname, "client/app", "app.js")
  },
  output: {
    path: path.join(__dirname, "build"),
    filename: "newapp.js",
    chunkFilename: "[name].js"
  },
  plugins: [
    //Typically you'd have plenty of other plugins here as well
    new webpack.DllReferencePlugin({
      context: path.join(__dirname, "client"),
      manifest: require("./build/vendor-manifest.json")
    }),
  ],
  module: {
    loaders: [
      {
        test: /\.js?$/,
        loader: "babel-loader",
        include: [
          path.join(__dirname, "client") //important for performance!
        ],
        query: {
          cacheDirectory: true, //important for performance
          plugins: ["transform-regenerator"],
          presets: ["es2015", "stage-0"]
        }
      },
      { test: /\.(scss|sass)$/, loader: 'style-loader' },
      { test: /\.html$/, loader: 'raw-loader' },
      { test: /\.css$/, loader: 'css-loader' }
    ]
  },
  resolve: {
    extensions: [".js"]
  }
};

and my dll.config:

var path = require("path");
var webpack = require("webpack");

module.exports = {
  entry: {
    dependencies: ["angular","lodash","style-loader","sass-loader","fs","fs-walk","node-sass","css-loader"],
  },
  node: {
    fs: 'empty'
  },

  output: {
    filename: 'vendor.bundle.js',
    path: '/Users/dimitri/NG6-starter/build',
    library: 'vendor_lib',
  },
  plugins: [new webpack.DllPlugin({
    name: 'vendor_lib',
    path: 'build/vendor-manifest.json',
  })]
};

How can I resolve this type of error ?


Solution

  • you are currently specifying just style-loader for loading your sass files. You will need to include css-loader and sass-loader.

    {
      test: /\.(scss|sass)$/,
      loader: ['style-loader', 'css-loader', 'sass-loader']
    }
    

    style-loader: creates style nodes from JS strings

    css-loader: translates CSS into CommonJS

    sass-loader: compiles Sass to CSS

    NOTE: Don't forget to install sass-loader using npm install --save sass-loader