Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Module parse failed: Unexpected character '@' (1:0)

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',
    })
  ]
};
like image 748
Paul Avatar asked Feb 25 '20 17:02

Paul


2 Answers

Try adding the below json to the rules array.

  {
    test: /\.(sass|less|css)$/,
    loaders: ['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.

like image 189
Prabhat Mishra Avatar answered Oct 24 '22 10:10

Prabhat Mishra


Thank You! It's working. ;)

   {
        test: /\.(sass|css|scss)$/,
        use: [
          'style-loader',
          'css-loader',
          {
            loader: "postcss-loader",
            options: {
              plugins: () => [
                require("autoprefixer")()
              ],
            },
          },
          'sass-loader',
        ]
      },
like image 24
Paul Avatar answered Oct 24 '22 12:10

Paul