7

I am currently building a react-express web app and today I ran into many bugs, The first issue was with Webpack-5. I solved it by downgrading the version to 4.0.3 but when I started the react-app, the CSS was not working so I thought it might be an error with Node JS version so I installed the latest version but that caused another bug so I installed the LTS 16.15.1 version but the CSS still did not work. So the next thing I did was reinstall tailwind but that still did not fix it. I don't receive any error messages in the console or in the terminal.

tailwind.config.js

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

postcss.config.js

export const plugins = {
  tailwindcss: {},
  autoprefixer: {},
};

package.json

"devDependencies": {
    "autoprefixer": "^10.4.7",
    "postcss": "^8.4.14",
    "sass": "^1.52.1",
    "tailwindcss": "^3.1.3",
    "typescript": "^4.7.3"
  }

Here is the link to the project if that helps in any way.

1

5 Answers 5

8

I had the same issue, the solution for me was in the content array in the tailwind.config.json where I specified the path to the folder where I what the styles to get appliedenter image description here

module.exports = {
  content: [
    "./pages/**/*.{js,ts,jsx,tsx}",  
    "./components/**/*.{js,ts,jsx,tsx}",
    "./page-section/**/*.{js,ts,jsx,tsx}",
  ],
  theme: {
    extend: {
      colors: {
        primary: "#366B45"
      },

      fontFamily: {
        sans: ["Inter", "sans-serif"],
      },
    },
  },
  plugins: [],
};
Sign up to request clarification or add additional context in comments.

2 Comments

shouldn't just have content: [ "./src/**/*.{js,tsx,jsx}", ], be sufficient though? As it involves the entire project. I'm still having issues setting this up and can't quite get an answer anywhere
@RafaelSantos nextjs projects dont have a src folder in the root by default
3

I finally fixed the issue by following this: https://www.smashingmagazine.com/2020/02/tailwindcss-react-project/. But am still not sure why it stopped working suddenly. The only problem with this solution is that on npm start it builds the CSS and outputs it to another file. The problem with that is that I have to restart the server everytime I make a change to the CSS.

Comments

3

Along with the above answers, I've figured that it usually boils down to either the "content" array within your tailwind.config.json, or if you're using something like Vite, it requires you to import tailwindcss within your vite.config.ts file, as following -

import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import tailwindcss from "tailwindcss";

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [react()],
  css: {
    postcss: {
      plugins: [tailwindcss()],
    },
  },
});

tailwind.config.ts -

/** @type {import('tailwindcss').Config} */
export default {
  content: ["./index.html", "./src/**/*.{js,jsx,ts,tsx}"],
  theme: { ... }
}

Note - The '...' within "theme" above just means your usual things within the rest of the object, my only aim is to bring your attention to the "content" array here.

Comments

0

Try to add the following in the index.css file

@tailwind base;
@tailwind components;
@tailwind utilities;

3 Comments

I had already done that, but it did not work
Try to restart the server
That’s the first thing I did but did not work
0

If you are building React Web app via Parcel, then make sure to include your index.html, index.css files inside your src folder.

For more info Follow this site: https://tailwindcss.com/docs/guides/parcel

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.