[Django]-Getting Module parse failed: Unexpected token (1:0) error when I try to import css file for a specific component in react

4👍

Webpack doesn’t understand CSS files out of box. You need to use css-loader with style-loader to handle CSS files.

module.exports = {
  entry: "./src/index.js",
  output: {
    path: path.resolve(__dirname, "./static/frontend"),
    filename: "[name].js",
  },
  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        use: {
          loader: "babel-loader",
        },
      },
      // Additional configuration to handle *.css files
      {
        test: /\.css$/i,
        use: ["style-loader", "css-loader"],
      },
    ],
  },
  // Other remaining configuration
};

Leave a comment