22

I'm a really beginner in Webpack and React. I want to use some npm (carousel multi react), but I can't. It's something wrong with my webpack.config. Unfortunetly I can't resolve this on my own, and I saw some similiar topics, but it doesn't working for me... or I just don't know how to implement solutions in my file.

ERROR in ./node_modules/react-multi-carousel/lib/styles.css 1:0 Module parse failed: Unexpected character '@' (1:0) You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders

const path = require("path");

const Html = require('html-webpack-plugin');

module.exports = {
  entry: [
    "whatwg-fetch",
    "./js/index.js",
  ],
  output: { 
    filename: "js/out.js",
    path: path.resolve(__dirname, "build")
  },
  devServer: {
    port: 3001,
  },
  module: {
    rules: [

      {
        test: /\.js$/,
        exclude: /node_modules/,
        use: {
          loader: "babel-loader",
        }
      },

      {
        test: /\.scss$/,
        use: [
          'style-loader',
          'css-loader',
          {
            loader: "postcss-loader",
            options: {
              plugins: () => [
                require("autoprefixer")()
              ],
            },
          },
          'sass-loader',
        ]
      },

      {
        test: /\.(jpg|jpeg|gif|png)$/,
        use: {
          loader: 'file-loader',
          options: {
            name: '[name].[ext]',
            publicPath: 'images',
            outputPath: 'images',
          }
        }
      },

      {
        test: /\.(eot|ttf|woff|woff2)$/,
        use: {
          loader: 'file-loader',
          options: {
            name: '[name].[ext]',
            publicPath: 'fonts',
            outputPath: 'fonts',
          }
        }
      },
    ]
  },

  plugins: [
    new Html({
        filename: 'index.html',
        template: './index.html',
    })
  ]
};
Paul
  • 381
  • 1
  • 4
  • 12
  • Does this answer your question? [Webpack babel 6 ES6 decorators](https://stackoverflow.com/questions/33801311/webpack-babel-6-es6-decorators) – azium Feb 25 '20 at 18:00
  • https://babeljs.io/docs/en/babel-plugin-proposal-decorators – azium Feb 25 '20 at 18:00

3 Answers3

22

Try adding the below json to the rules array.

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

Also install the required npm modules for the above loaders, or else you can also try with adding test: /\.(sass|css)$/, to your current setup.

nelly22
  • 3
  • 3
Prabhat Mishra
  • 951
  • 2
  • 12
  • 33
12

Thank You! It's working. ;)

   {
        test: /\.(sass|css|scss)$/,
        use: [
          'style-loader',
          'css-loader',
          {
            loader: "postcss-loader",
            options: {
              plugins: () => [
                require("autoprefixer")()
              ],
            },
          },
          'sass-loader',
        ]
      },
Paul
  • 381
  • 1
  • 4
  • 12
2

Try,

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

Then add this code into your webpack config file,

 {
   test: /\.(sass|less|css)$/,
   use: ["style-loader", "css-loader", 'sass-loader'],
 },
Shahnad S
  • 983
  • 10
  • 17