webpackwebpack-dev-serversass-loaderextract-text-pluginextracttextwebpackplugin

Module build failed: Error: "extract-text-webpack-plugin" when import .scss file


this issue occurred when I import .scss file in react component.

enter image description here

package.json

"scripts": {
  "dev": "source ./.env && nodemon server.js"
},
"devDependencies": {
  "babel-core": "^6.26.0",
  "babel-loader": "^7.1.4",
  "babel-preset-env": "^1.6.1",
  "babel-preset-react": "^6.24.1",
  "css-loader": "^0.28.11",
  "extract-text-webpack-plugin": "^4.0.0-beta.0",
  "nodemon": "^1.17.2",
  "sass-loader": "^6.0.7",
  "style-loader": "^0.20.3",
  "webpack": "^4.4.1",
  "webpack-dev-middleware": "^3.1.0",
  "webpack-dev-server": "^3.1.1"
}

webpack.config.js

module.exports = {
  mode: 'development',
  entry: './client/app/index.js',
  output: {
    path: `${__dirname}/dist`,
    publicPath: '/',
  },
  devtool: 'source-map',
  module: {
    rules: [
      {
        test: /\.jsx?$/,
        include: `${__dirname}/client`,
        loader: 'babel-loader',
      },
      {
        test: /\.scss$/,
        loaders: [
          'style-loader',
          'css-loader',
          'sass-loader'
        ]
      }
    ]
  }
};

server.js

-----

if (process.env.NODE_ENV === 'development') {
  const compiler = webpack(webpackConf);
  app.use(webpackMiddleware(compiler, {
    publicPath: webpackConf.output.publicPath,
    contentBase: './client',
    hot: true,
    stats: {
      colors: true
    }
  }));
}
----

It's very wired. I don't use extract-text-webpack-plugin.

but the issue is about it.

I try downgrade webpack to v3. but still failed...

Have anyone can help me to fix it...


Solution

  • First. If you use sass-loader, you need to go with this configuration as recommendation from github.

    Second: rule.loaders is wrong configuration. See the link

    Third: extract-text-webpack-plugin is dependency from webpack.