Incorrect Configuration of Tailwind v3 in React and Webpack

Can anyone help me figure out why styles are not being applied when integrating Tailwind v3 into my React v17 / Webpack v5 app? I am not receiving any errors, so it's unclear what may be missing.

Here is the relevant file structure:

/client/index.js

import "./components/tailwind.css";
import React from "react";
import ReactDOM from "react-dom";
import { BrowserRouter as Router, Routes, Route } from "react-router-dom";
import "core-js/stable";
import "regenerator-runtime/runtime";
import App from "./components/App.jsx";
import Login from "../client/components/Auth/Login.jsx";
import Signup from "../client/components/Auth/Signup.jsx";

ReactDOM.render(
  <Router>
      <Routes>
        <Route path="/" element={<App />}>
          <Route path="login" element={<Login />} />
          <Route path="signup" element={<Signup />} />   
      </Routes>
  </Router>,
  document.getElementById("myapplication")
);

/client/components/App.jsx

import React from "react";
import { useLocation, Outlet } from "react-router-dom";
import NavBar from "./NavBar/NavBar.jsx";
import Home from "./Home/Home.jsx";
import Footer from "./Home/Footer.jsx";

function App() {
  const location = useLocation();

  return (
    <main>
      <NavBar />
      <Outlet />
      {(location.pathname == "/" || location.pathname == "") && <Home />}

      {(location.pathname == "/" ||
        location.pathname == "" ||
        location.pathname.includes("resources")) && <Footer />}
    </main>
  );
}

export default App;

/client/components/tailwind.css

@import "tailwindcss/base";
@import "tailwindcss/components";
@import "tailwindcss/utilities";

/public/index.html

<!DOCTYPE html>
<html>
  <head>
    <title>MyApplication</title>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <!-- Webpack Bundle -->
    <script defer type="text/javascript" src="/myapplication-bundle.js"></script>   
  </head>
  <body>
    <div id="myapplication"></div>
  </body>
</html>

postcss.config.js

module.exports = {
  plugins: [
    require("tailwindcss")("./tailwind.config.js"),
    require("autoprefixer"),
  ],
};

/tailwind.config.js

module.exports = {
  content: ["./components/**/*.{js,jsx}", "../public/*.html"],
};

/wepback.config.js

const path = require("path");
const ProgressBarPlugin = require("progress-bar-webpack-plugin");
const webpack = require("webpack");

module.exports = {
  entry: path.join(__dirname, "/client/index.js"),
  output: {
    filename: "myapplication-bundle.js",
    path: path.join(__dirname, "/public"),
  },
  module: {
    rules: [
      {
        test: /\.(js|jsx)$/,
        include: [path.join(__dirname, "/client/"), /node_modules\/xhr/],
        exclude: /node_modules/,
        loader: "babel-loader",
        options: {
          presets: ["@babel/preset-react", "@babel/preset-env"],
        },
      },
      {
        test: /\.css$/i,
        use: ["style-loader", "css-loader", "postcss-loader"],
      },
    ],
  },
  mode: "development" === process.env.NODE_ENV ? "development" : "production",
  devtool: "source-map",
  resolve: {
    extensions: [".js", ".jsx"],
  },
  plugins: [
    new ProgressBarPlugin(),
    new webpack.ProvidePlugin({
      process: "process/browser",
    }),
  ],
  resolve: {
    alias: {
      request$: "xhr",
    },
  },
};

/package.json

  "scripts": {
    "server-dev": "NODE_ENV=development nodemon main",
    "server-prod": "NODE_ENV=production node main",
    "react-dev": "NODE_ENV=development webpack --watch",
    "react-prod": "NODE_ENV=production webpack",
    "test": "NODE_ENV=test jest --coverage"
  },

Answer №1

When configuring tailwind.config.js, be sure to include the following:

module.exports = {
  content: [
    "./src/**/*.{js,jsx,ts,tsx}",
  ],
  theme: {
    extend: {},
  },
  plugins: [],
}

For more information on using Tailwind CSS with React, check out the documentation here:

https://tailwindcss.com/docs/guides/create-react-app

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Creating a bootstrap form field that spans 100% in width:

I am encountering an issue with two column divs in a row, each containing two text fields. When resizing on mobile, the width of the textbox is not expanding to 100% and looks unattractive. Below is my Bootstrap code, but strangely, the width looks fine f ...

Insert a triangle shape at the bottom of the material design tab with the class mat-ink-bar

I'm trying to update the appearance of the mat-ink-bar in the Angular material tab. My goal is to achieve a design similar to this: Jsfiddle example The issue I'm facing is that the mat-ink-bar is already positioned as absolute, making it diffi ...

Building unique CSS classes with Material UI v5 theme - A step-by-step guide

Incorporating Material UI v5 into my application has been a smooth process, except when it comes to using react-d3-tree for rendering SVG tree charts. This library allows for custom CSS class names to be added to the <path> elements that connect the ...

Disappearing Act: The Vanishing React.js Dialog Component that Lurks

Currently, I am utilizing a Dialog component from Material-UI and, overall, it is functioning correctly. However, there is an issue where if I click away from the Dialog, it disappears as expected, but occasionally it remains in the DOM with an opacity of ...

How can I make the Search String stand out in the mysql result?

Here's the code I've written up to now <form method="post" name="search"> <input type="search" name="k" placeholder="Enter Keywords"> <input type="submit" value="Search"> </form> <? $skw = $_POS ...

An issue arises when attempting to execute npm with React JS

I encountered an error after following the setup steps for a react configuration. Can anyone provide assistance? This is the content of the webpack.config.js file: var config = { entry: './main.js', output: { path:'/', ...

What causes the discrepancy in button appearance between Next.js 14, next/font, and Tailwind CSS?

I am currently facing a challenge in upgrading to nextjs 14 due to my struggle with incorporating next/font. I have two buttons with identical tailwind classes, except for the last className that pertains to nextjs font. Below is the code snippet: import ...

The Google Rich Result Testing Tool encountered an issue: Parsing error detected - a '}' or object member name is missing

Visit my website: www.bharatpharmatech.com I have implemented my code using Next.js Here is the schema I am utilizing: { "@context": "https://schema.org/", "@type": "WebSite", "name": "Bharat Pharmate ...

Troubleshooting: Django project not functioning properly post transfer from Windows to Mac

Using Django 3.1.7 on a MacBook Pro now, I recently moved the Django project from a Windows 10 machine. Despite setting up the database and superuser again, running pipenv sync didn't result in serving any of my URLs or Admin page CSS styles. The serv ...

Step-by-step guide for importing a JSON file in React typescript using Template literal

I am facing an error while using a Template literal in React TypeScript to import a JSON file. export interface IData { BASE_PRICE: number; TIER: string; LIST_PRICE_MIN: number; LIST_PRICE_MAX: number; DISCOUNT_PART_NUM: Discout; } type Discoun ...

What is the best way to apply styling to an image that is contained within the document.write function?

I'm looking to customize the design of this cat image, but I'm struggling to locate where to incorporate the div class. It's likely a basic step, but as a beginner in JavaScript, I'm hoping that someone can assist me. document.write(&ap ...

Position the div in the center of a container that is 100% width and has floating elements with dynamic widths

I am looking to align 3 divs inside a container div, with the arrangement of [LEFT] [CENTER] [RIGHT]. The container div should be 100% wide without a fixed width, and I want the center div to stay centered even when resizing the container. The left and ...

Tips for creating gaps between wells within a Bootstrap row

Utilizing bootstrap, I am aiming to position two wells side by side without them being squeezed right next to each other. However, I am encountering some issues with achieving this. Here's the code snippet I am currently using: <div class="contai ...

vertical-align applied to table cells creating a floating effect

I have discovered that by adjusting the display property of the containing block to table and enclosing descendant block boxes in boxes with display property set to table-cell and vertical-align property set to top, it produces the same effect as if the fl ...

Utilizing Redux with React class components: A comprehensive guide

I have been attempting to integrate Redux with React Class using TypeScript, following the guidelines provided in this tutorial. However, I am encountering numerous compilation errors and feeling overwhelmed as to where to begin troubleshooting. It is cl ...

Incorporate the Beamer platform from app.getbeamer.com with Next.js version 13

I am currently in the process of working on a Next.js 13 project and I am interested in incorporating Beamer () to make announcements about updates and new features on my web application. I have managed to obtain the Beamer script from my Beamer account, ...

Encountered a 'node:internal/modules/cjs/loader:1146' error while setting up a React application

Encountering these console errors node:internal/modules/cjs/loader:1146 throw err; ^ Error: Module '../../package.json' not found Require stack: - C:\Users\adity\AppData\Roaming\npm\node_modules\npm\li ...

Utilize AngularJS to import a unique custom css stylesheet for every individual webpage

Is there a way to apply different stylesheets to each page without mixing classes? For example, how can I link style.css to index.html and about.css to about.html? This is my AngularJS code: // Define module var myApp = angular.module('myApp', ...

Icon bar struggling to contain voluminous material card content

I've incorporated Material UI cards into my project and have an icon bar at the bottom of each card. However, the media within the card is overflowing onto the icon bar, causing a layout issue as illustrated in this screenshot: https://i.sstatic.net/ ...

What are the steps to create a responsive form using CSS?

I have a screenshot below that needs to be recreated using HTML/CSS. This design should be consistent in both desktop and mobile views. https://i.stack.imgur.com/cnfHt.png Currently, I have managed to replicate this in a JSFiddle which looks good on desk ...