Filth
Filth

Reputation: 3228

Extract Text Plugin 'loader is used without the corresponding plugin' - React, Sass, Webpack

I'm trying to get SASS compilation running on my React + Webpack project and keep running into this error:

Module build failed: Error: "extract-text-webpack-plugin" loader is used without the corresponding plugin

Followed the guidelines from this tutorial: Link

Here is my webpack.config.js

Any suggestions?

const debug = process.env.NODE_ENV !== "production";
const webpack = require('webpack');
const path = require('path');
const ExtractTextPlugin = require("extract-text-webpack-plugin");

module.exports = {
  context: path.join(__dirname, "src"),
  devtool: debug ? "inline-sourcemap" : null,
  entry: "./js/client.js",
  module: {
    loaders: [
      {
        test: /\.jsx?$/,
        exclude: /(node_modules|bower_components)/,
        loader: 'babel-loader',
        query: {
          presets: ['react', 'es2015', 'stage-0'],
          plugins: ['react-html-attrs', 'transform-class-properties', 'transform-decorators-legacy'],
        }
      },
      {
          test: /\.scss$/,
          loader: ExtractTextPlugin.extract('css!sass')
      }
    ]
  },
  output: {
    path: __dirname + "/src/",
    filename: "client.min.js"
  },
  plugins: debug ? [] : [
    new ExtractTextPlugin('dist/styles/main.css', {
        allChunks: true
    }),
    new webpack.optimize.DedupePlugin(),
    new webpack.optimize.OccurenceOrderPlugin(),
    new webpack.optimize.UglifyJsPlugin({ mangle: false, sourcemap: false }),
  ],
};

Upvotes: 4

Views: 5678

Answers (3)

Rahil Lakhani
Rahil Lakhani

Reputation: 408

Error occurred for me because of incorrect format of parameters - refer this -> https://github.com/webpack-contrib/extract-text-webpack-plugin/issues/207

my code looks like this module: { rules: [ { test: /\.scss$/, use: ExtractTextPlugin.extract({ fallback: 'style-loader', use: ['css-loader', 'sass-loader'] }) }] }, plugins: [ new ExtractTextPlugin({ filename: 'css/[name].css', disable: false, allChunks: true }) ]

Upvotes: 0

Paul  Kaspriskie
Paul Kaspriskie

Reputation: 201

So I solved this by installing style-loader, css-loader, and sass-loader.

npm install style-loader css-loader sass-loader --save-dev

Then I used them like this.

{
  test: /\.scss$/,
  loader: ExtractTextPlugin.extract("style-loader","css-loader!sass-loader"),
 },

Upvotes: 2

Michael Jungo
Michael Jungo

Reputation: 32972

When your NODE_ENV is not production, you don't include any plugins.

plugins: debug ? [] : [
  new ExtractTextPlugin('dist/styles/main.css', {
    allChunks: true
  }),
  new webpack.optimize.DedupePlugin(),
  new webpack.optimize.OccurenceOrderPlugin(),
  new webpack.optimize.UglifyJsPlugin({ mangle: false, sourcemap: false }),
],

So when debug is true, you'll have

plugins: []

But you're still using it in the .scss loader.

To solve it, you can add it to these plugins as well (so you don't have the production plugins like UglifyJsPlugin):

plugins: debug
  ? [
      new ExtractTextPlugin("dist/styles/main.css", {
        allChunks: true
      })
    ]
  : [
      new ExtractTextPlugin("dist/styles/main.css", {
        allChunks: true
      }),
      new webpack.optimize.DedupePlugin(),
      new webpack.optimize.OccurenceOrderPlugin(),
      new webpack.optimize.UglifyJsPlugin({ mangle: false, sourcemap: false })
    ]

Or you don't use the ExtractTextPlugin in your .scss loader (this won't extract them to a css file in development):

{
  test: /\.scss$/,
  loader: debug ? 'css!sass' : ExtractTextPlugin.extract('css!sass')
}

Upvotes: 5

Related Questions