Tailwind CSS classes is not working in my project
Asked Answered
F

41

51

Here is my HTML link https://play.tailwindcss.com/fbB4GCL0ht

Visual Studio Code setup pictures

Tailwind.Config.js

All files

warn - No utility classes were detected in your source files. If this is unexpected, double-check the content option in your Tailwind CSS configuration.
warn - https://tailwindcss.com/docs/content-configuration Done in 320ms.

This is showing my Visual Studio Code Terminal. What should I do? I have also added base components and utilities.

Fleuron answered 10/2, 2022 at 18:56 Comment(7)
How did you intstall Tailwind? Do you have a tailwind.config.js file in your project? Without knowing what you've done and what file(s) you have, there's no way to diagnose the problemJobi
Yeah I have that fileFleuron
Edit your initial post to describe how you installed Tailwind, and add what that file currently has in it. Also, did you add @tailwind base; @tailwind components; and @tailwind utilities; in your main CSS fileJobi
As you said I just added please help me with this problem.Fleuron
github.com/ali09-github/Tailwind_projectFleuron
If your avenues of solution fail to whatever degree, consider that Tailwind has caused you more trouble than its worth already and stop using it. One should never use Tailwind in a really large project because associated styles are not grouped - so then what real value does it bring? Small websites rapid development - but this is not the primary problems they claim to solve! (problems such as complex class naming, and avoid CSS rule collisions)Lulu
Why should I not upload images of code/data/errors?. A minimal reproducible example of the code needs to be in the question itself, as text.Visual
S
82

This error is due to Tailwind not finding any classes to scan in what it 'thinks' is your HTML code directories.

This section in your tailwind.config.js file determines which files are scanned to be processed by Tailwind CSS:

  content: [
    './pages/**/*.{html,js}',
    './components/**/*.{html,js}',
  ],

This corrected the issue for me.

Official documentation: Content Configuration

Slideaction answered 14/2, 2022 at 15:58 Comment(4)
github.com/ali09-github/Tailwind_projectFleuron
also make sure to include the new app directory: './app/**/*.{js,ts,jsx,tsx}',Volumeter
Also, if you have not yet added a single tailwind class to your html, the same warning message will be in the console, something along the lines of "no utility classes were found", mind you this is the same warning message as if it cannot find your index.html at all.Perceval
If you use Next.js with MDX and have a mdx-components.tsx file for customizing built-in components, make sure to include this file in tailwind.config.js under content like './mdx-components.tsx',Groundhog
S
21

I was facing the same problem. After some tests, I found a solution, but I don't know the right solution or why this is occurring, so if anyone has a clue, let us know.

content: [
    './pages/**/*.tsx',
    './components/**/*.tsx',
  ],

or

content: [
        './pages/**/*.jsx',
        './components/**/*.jsx',
      ],

Tailwind is not recognizing the options between {}, so I just specifying what type I'm working on, .tsx or .jsx. And I was leading to a wrong path, so check this, as well.

Spangle answered 18/2, 2022 at 17:31 Comment(3)
Yes... the curly braces {} were the issue for me as well. I'm using VueJS 3 in case that helps anyone.Graver
I found that my mistake was that I have whitespaces in my paths. I accidentially had .../*{js, jsx, ts, tsx} but it should have been .../*.{js,jsx,ts,tsx}.Winfield
you need to update the answer and state the project framework you are using. that syntax is VUE. Please update the answer.Pugnacious
W
19

Although I added content in tailwind.config, it was still giving warnings.

I was running command to build the output:

npx tailwindcss -i ./input.css -o ./build/output.css

added -cli to the command and it worked for me:

npx tailwindcss-cli -i ./input.css -o ./build/output.css
Wahkuna answered 10/7, 2022 at 18:54 Comment(3)
This fixes it for me, why does this work?Footstep
Be careful with that, tailwindcss-cli hasn't been updated since 2020. It does fix the issue for me for some reason...Shiftless
Wow, fixes the issue for me too. But why doesn't just 'npc tailwind-css' work? Have you been able to figure it out @GuidoTarsia?Wallaroo
A
11

I had this issue too, but I may have solved it. Originally content in my tailwind.config.js file looked like this:

content: ["./src/**/*.{html,js}"]

I noticed that my App.js file was actually App.jsx so I just inserted single letter 'x' into that line:

content: ["./src/**/*.{html,jsx}"]

It seems to have worked.

Armond answered 24/2, 2022 at 11:19 Comment(0)
A
9

Your tailwind.config.js file can’t find your index.html file.

In the Tailwind CSS configuration file add your file path into content array './index.html',

You have to define your file path into content like below:

module.exports = {
  content: ["./src/**/*.{html,js}",

  '*.{html,js}'], // Like this

  theme: {
    extend: {},
  },
  plugins: [],
}

By the way, if you have different file extensions like .ts, .jsx, etc., you have to define the file extension in content: ['./*.{html,js,ts,jsx}']

Automotive answered 2/3, 2022 at 17:54 Comment(1)
The docs explicitly state to not use overly broad wild cards: tailwindcss.com/docs/…Motif
B
6

Don't use the curly braces; instead, specify the following.

module.exports = {
  content: [
    './src/**/*.html',
    './src/**/*.js',
    './public/**/*.html',
    './public/**/*.js'
  ],
  theme: {
    extend: {},
  },
  plugins: [],
}
Bootblack answered 28/4, 2022 at 14:8 Comment(1)
Curly braces are just fine and are used in the official docs extensively: tailwindcss.com/docs/content-configurationMotif
O
6

I think I've found the answer to the problem of Tailwind not building classes.

Besides the config of tailwind.config content sources, what really matters is:

From which folder you start your app with ng serve

For example, my tailwind.config file is:

module.exports = {
  content: ["app.component.html", "product/product.component.html", "home/home.component.html"]
  theme: {
    extend: {},
  },
  plugins: [], 
}

for Tailwind to find the classes in those three templates I have to start Angular from /src/app/ folder with ng serve.

If I start Angular from the /src/ folder then Tailwind will not find any classes.

Orr answered 4/8, 2022 at 6:44 Comment(2)
this is a duplicate answer, using regex is optimal.Pugnacious
@Pugnacious what do you mean?Asafoetida
S
5

If you use Vite then configure in file tailwind.config.js:

 content: ["./src/**/*.{js,jsx,ts,tsx}", "./public/index.html"]

Or you use Yarn, Npm, etc... then configure in file tailwind.config.js:

 content: [
        "./pages/**/*.{js,ts,jsx,tsx}",
        "./components/**/*.{js,ts,jsx,tsx}",
    ],
Secretion answered 19/4, 2022 at 8:2 Comment(0)
K
5

I was facing the same problem, the solution is to make sure your content configuration is correct. refer

  1. In your tailwind.config.js: Make sure the content source is pointing to your HTML files that are using tailwind. refer
module.exports = {
  content: [
    './components/**/*.{html,js}',
    './pages/**/*.{html,js}',
    './index.html',
  ],
  theme: {
    extend: {}
  },
  plugins: []
}
  1. Restart the Tailwind CLI build process
npx tailwindcss -i ./src/input.css -o ./dist/output.css --watch

** Ensure there are no warning messages regarding invalid file paths.

Katherinakatherine answered 29/10, 2022 at 8:15 Comment(5)
Great! this worked well for me. I'm using angular 15.2.3. I tried all the solutions above but none of them worked. I keep facing the same warning.Neighborhood
Oh finally worked, thanks!Tekla
please state the framework you are using. this helps when debugging.Pugnacious
@Pugnacious You can refer framework guide by tailwind docs tailwindcss.com/docs/installation/framework-guidesKatherinakatherine
The docs official recommend against overly broad wildcard patterns: tailwindcss.com/docs/…Motif
B
2

Like others said it depends if you are working with JS, TypeScript, or even HTML. In each case, you need to say the config to which files it will apply.

This is my config and I work with TypeScript:

/** @type {import('tailwindcss').Config} */
module.exports = {
    purge: ["./src/components/**/*.tsx", "./pages/**/*.tsx"],
    theme: {
        extend: {},
    },
    variants: {},
    plugins: [require("tailwindcss"), require("precss"), require("autoprefixer")],
};
Bookrest answered 23/8, 2022 at 18:10 Comment(1)
Thanks buddy. This worked for me for my next.js project.Stereotypy
B
2

In addition to the other solutions, this can happen if you've changed the prefix value in your configuration file.

Bozen answered 17/10, 2022 at 14:32 Comment(0)
M
2

You will also see this warning if you haven't actually set any class statements.

So, if you're starting a new project, and you're 100% sure your config file is correct, make sure you have at least one class statement in one of your files.

For example

<div class="w-full">Hello</div>
Mcallister answered 12/11, 2023 at 1:53 Comment(0)
C
1

This depends on the file you are working on. For example, if you're working on .js and .html file then you need to specify it in your tailwind.config.js file like this:

content: ["./src/**/*.{html,js}"]

If you're also working on .jsx file, then you only have to add it to your configuration file:

content: ["./src/**/*.{html,js,jsx}]
Cwmbran answered 21/3, 2022 at 19:44 Comment(0)
N
1

Just add this to into global.css

@tailwind variants;

Need answered 23/3, 2022 at 15:53 Comment(1)
This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From ReviewHannibal
A
1

I had a similar problem where some tailwind styles were working and other ones were not. After trying everything on this thread I got the impression that it could be something to do with adding the wrong object in the tailwind config. I remembered that I had added some bespoke fontsizes recently and had added this directly in the theme object. I moved it to the extension object and it worked immediately. For example:

Not working:

enter image description here

Working:

enter image description here

Aetolia answered 31/8, 2022 at 8:47 Comment(0)
A
1

Make sure that in content, the string doesn't contain spaces: {.js,.jsx} instead of {.js, .jsx}.

Aptitude answered 23/9, 2022 at 0:5 Comment(0)
G
1

Originally I used it well, but when i builded a new project i found it was not working anymore. I have tried many solutions and tried to check what I did wrong, but in the end, i found it just a matter of path. so i mean, you need to check the path, "./pages/......"or"./src/pages/......."

Glasses answered 28/9, 2022 at 15:42 Comment(1)
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Davedaveda
T
1

I got the same error. But when I started adding tailwind classes to the components and restarted the server, it's gone.

I think it might due to no class names found in any of the files it scanned.

Tubular answered 11/10, 2022 at 6:41 Comment(2)
Yeah! I have that same problem but now its fixedFleuron
This was why it showed up on my machine. Thanks.Flipper
B
1

I had to delete my package-lock.json and recreate with npm install.

I had tried everything up and to that point but this worked.

Burd answered 24/10, 2022 at 14:26 Comment(0)
A
1

Some frameworks hide their main HTML entry point in a different place than the rest of your templates (often public/index.html), so if you are adding Tailwind classes to that file make sure it’s included in your configuration as well:

Don't forget your HTML entry point if applicable

tailwind.config.js

  content: [
    './public/index.html',
    './src/**/*.{html,js}',
  ],
  // ...
}
Alissaalistair answered 26/10, 2022 at 5:50 Comment(0)
S
1

It worked when I removed the dot before the curly braces like content: ["./src/**/*{js, jsx,}"] or add them individually like content: ["./src/**/*{.js, .jsx,}"]

I don't really understand why but I get an error when I configure it like content: ["./src/**/*.{js, jsx,}"]

Shaper answered 1/1, 2023 at 18:55 Comment(1)
I'm having the same problem. Did you find out why this warn appear when using this content: ["./src/**/*{.js, .jsx,}"]?Nationalize
E
1

I'm using Vite inside a monorepo (turborepo). Prefixing the content glob with __dirname fixed it for me:

{
  content: [
    __dirname + "./index.html", 
    __dirname + "/src/**/*{js,ts,jsx,tsx}"
  ]
}

Elation answered 14/5, 2023 at 16:43 Comment(0)
F
1

After you read the Tailwind CSS installation carefully and did all the steps, make sure, when you run the project (npm run or ng serve or anything else) be at the same directory that package.json is.

Follansbee answered 5/6, 2023 at 2:26 Comment(0)
M
1

Just in case someone is playing around with only HTML and Tailwind CSS (no JavaScript), as I was :), you need a server running to serve the Tailwind CSS styles or adjust the path to where the CSS file is.

If you're using Visual Studio Code you can use for example the extension Live Server to start a server to host your static HTML files.

If you want to run your HTML file without a server, then make sure to adjust the link to the absolute path of your CSS file, e.g.: <link href="/home/john/project/dist/output.css" rel="stylesheet">

As mentioned above, when declaring multiple file types in the tailwind.config.js => content make sure to don't have any space between them! And always double-check your paths.

Happy styling with Tailwind CSS!

Matejka answered 29/8, 2023 at 19:8 Comment(2)
Re "Visual Studio": Do you mean Visual Studio Code?Stank
Yes :) I updated the answer to reflect that.Matejka
M
0

The path may have been changed in your project. Check your path and configure accordingly. E.g., if you have moved your pages & components to your src folder, add the following to your Tailwind config file.

  content: [
    "./src/pages/**/*.{js,ts,jsx,tsx}",
    "./src/components/**/*.{js,ts,jsx,tsx}",
  ],
Meanie answered 25/4, 2022 at 10:11 Comment(0)
C
0

I had the same problem. In my case, I had spaces before file extensions in tailwind.config.js.

Wrong version:

  content: [
      "./assets/**/*.{vue, js, ts, jsx, tsx}",
      "./templates/**/*.{html, twig}"
  ],

Correct version:

  content: [
      "./assets/**/*.{vue,js,ts,jsx,tsx}",
      "./templates/**/*.{html,twig}"
  ],
Caye answered 27/5, 2022 at 10:4 Comment(0)
P
0

It basically looks for your component files, so you have to configure the path that way.

Suppose you just started a react project, added tailwind, and you want to check. in that case you can add the following to your, tailwind.config.js file. This will locate the App.jsx file in your src directory of the project.

  content: [
    './src/.{html,jsx}',
  ],

On another case, if you have a components directory inside of which you different directories for different components you can add the following to your tailwind.config.js file.

  content: [
    './src/**/*.{html,jsx}',
  ]
Pedicular answered 7/6, 2022 at 19:27 Comment(0)
G
0

Just Import TailwindCSS into your pages/_app.js file:

import '../styles/globals.css'
import 'tailwindcss/tailwind.css';

function MyApp`enter code here`({ Component, pageProps }) {
return <Component {...pageProps} />
}

export default MyApp
Gentilism answered 28/6, 2022 at 10:31 Comment(1)
Please provide an explanation to your code - it is very hard to understand something when it isn't explained. Read - stackoverflow.com/help/how-to-answerPragmatics
U
0

enter image description here

Make sure your Tailwind config file doesn't contain duplicated properties. In my case, the content property had been repeated twice. After removing one of them it worked as supposed to.

Umbra answered 4/7, 2022 at 19:33 Comment(0)
H
0

Ran into this issue when doing an upgrade to 3.1.x from 2.2 and did not complete all the upgrade steps.

Specifically, I added the content entry but did not remove the purge entry

module.exports = {
  purge: [],
  content: ['./src/**/*.{js,jsx,ts,tsx}']

After I removed the purge line, the util classes where included.

module.exports = {
  content: ['./src/**/*.{js,jsx,ts,tsx}']

Holton answered 15/7, 2022 at 17:45 Comment(0)
O
0

I had the same problem, check your path to your templates in tailwind.config.js.

Path might begin with .. instead of .:

content: [
'../src/app/app.component.html'
]

instead of

content: [
'./src/app/app.component.html'
]

This was my problem.

Orr answered 2/8, 2022 at 10:5 Comment(0)
F
0

This is what worked in my case. I had to use path in the tailwind.config.js file to make it work.

const { join } = require('path');

module.exports = {
  content: [join(__dirname, 'src/**/*.{js,ts,jsx,tsx}')],
  theme: {
    extend: {},
  },
  plugins: [],
};
Fingernail answered 19/8, 2022 at 14:16 Comment(0)
T
0

For anyone that is using Tailwind with Next.js and Tailwind CSS. Add this to your content value:

    content: [
    './pages/**/*.{js,ts,jsx,tsx}',
    './components/**/*.{js,ts,jsx,tsx}',
  ],

Attention!

The warning will still there even if you corrected the content path,

You need to add minimum one Tailwind CSS class to one of the paths you mentioned in content, just use a tailwind css in your project, and the warning will disappear. :)

Trista answered 30/8, 2022 at 17:46 Comment(0)
Z
0

I have tried a few things trying to get the styles to be applied with Tailwind CSS. I did eventually add the CDN script tag to my index which basically made the class styles pull through to the frontend.

<!doctype html>
<html>
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
// CDN added which made everything work..is this a good approach?
  <script src="https://cdn.tailwindcss.com"></script>
</head>
<body>
  <h1 class="text-3xl font-bold underline">
    Hello world!
  </h1>
</body>
</html>
Zurkow answered 9/12, 2022 at 11:43 Comment(3)
In production builds you want to avoid this option if you want to avoid the huge 4MB all-inclusive-file. Most people won't use most classes provided by TailwindCSS, so 4MB will shrink to perhaps 50K on a given project for production.Lulu
Thanks for the insight, I thought you could tell by my tone of my submission that I was sad I could not get it to work and use tailwindcss for a side project. However I am working on a tailwindcss project at work so I'll look into why config isn't working. Thanks for the reasoning though!Zurkow
Tailwind does not fully work with Angular Material Components without extra preprocessing configuration. Tailwind addresses a real css complexity challenge the wrong way. 1) We WANT locally scoped / shadow dom css rules 2) We WANT all CSS classes to be covered INCLUDING rule names such as margin-inline-end - but they are not supported directly in Tailwind 3) We do not want brittle complex silently failing JIT compilation of classes 4) We do not want to be at risk of Tailwind not supporting core CSS specs that come in the future Do not use a library because it is trendy.Lulu
C
0

I have also got the same error. Look at this configuration file:

/** @type {import('tailwindcss').Config} */
module.exports = {
  content: [
    "./pages/**/*.{js,ts,jsx,tsx}",
    "./Components/**/*.{js,ts,jsx,tsx}",
  ],
  theme: {
    extend: {},
  },
  plugins: [],
}

Make sure if you create a folder of Components in your root folder, it should be Components in your taiwind.config.js file.

Cabob answered 10/1, 2023 at 15:48 Comment(0)
R
0

Just btw, when your content is bloated with a bunch of different file paths that have all the exact same pattern except for 1 folder like example:

content: [
  './src/app/**/*.{js,ts,jsx,tsx}',
  './src/pages/**/*.{js,ts,jsx,tsx}',
  './src/components/**/*.{js,ts,jsx,tsx',
  './src/hooks/**/*.{js,ts,jsx,tsx}',
],

You can put the folder names in one like this:

content: ['./src/(app|pages|components|hooks)/**/*.{js,ts,jsx,tsx}'],
Roundelay answered 18/6, 2023 at 9:45 Comment(0)
T
0

Please check the image for tailwind.config.js where it is being put and what is written on the file

Check the files structure on the left side and run:

npx tailwindcss -i ./src/styles.css -o ./public/styles.css --watch

The smart Tailwind CSS will scan the folder for file and it will be successful!

Tuchun answered 2/10, 2023 at 12:5 Comment(0)
N
0

For anyone still facing this issue, you can just past the below snippet into your tailwind.confg.js file.

/** @type {import('tailwindcss').Config} */
export default {
  content: ['./**/*.{html,tsx}'],
  theme: {
    extend: {},
  },
  plugins: [],
}
Neusatz answered 3/4 at 12:3 Comment(0)
B
0

That's because your Path directory in your tailwind.config.js is Incorrect.

for example, if you have an SRC folder, it should be like this :

  content: [
    './src/app/**/*.{html,js,jsx,ts,tsx}', // Include all JavaScript/TypeScript files in the pages directory
    './src/components/**/*.{html,js,jsx,ts,tsx}', // Include all JavaScript/TypeScript files in the components directory
  ],

enter image description here

Barron answered 8/4 at 17:22 Comment(0)
T
0

This error is due to Tailwind not finding any classes to scan in what it 'thinks'. For, e.g: if you're running public/index.html file in a browser then follow the below steps.

  1. We need to create tailwind.config.js file. This file contains tailwind configuration like on which file needs to apply css or theme etc.

  2. To create a file hit a command on your terminal

    npx tailwindcss init

This command will create tailwind.config.js in your root folder. Now, we need to modify the configuration. We will tell tailwind which files need to apply tailwind css and theme etc. In our case we're running public/index.html. So configuration like as below

module.exports = {
  content: [
    "./src/**/*.{html,js}",
    "./public/**/*.{html,js}"
  ],
  theme: {
    extend: {},
  },
  plugins: [],
}

Here, I want to compile files that are present in a public folder and src folder. So I've added both of them.

Try now. Good Luck.!

Transcription answered 1/5 at 7:1 Comment(0)
C
0

I was using Angular 11 with Tailwind ^3.4.4 and was facing an abrupt issue where the Tailwind classes were partially loaded during serve. For example, class flex would work but not max-w-full.

Tailwind was not recognizing the HTML changes that the new classes were added to any element and whenever I change any .scss file or tailwind.config.js file the changes would reflect. To overcome this, you need to perform the following:

  • Check the content property: It is the soul of Tailwind, if you have made a mistake in this file, no matter what, the Tailwind classes won't work. Like others and as stated in Tailwind-Angular docs, I was using the following value for content in my config:
content: ["./src/**/*.{html,ts,js}"]
  1. Mind you this paths here are relative to PROJECT ROOT as stated in official docs:

Paths are relative to your project root, not your tailwind.config.js file, so if your tailwind.config.js file is in a custom location, you should still write your paths relative to the root of your project.

Also, if you have your tailwind.config.js file situated in some nested directory, the path will change accordingly. Mine was at the root of the project.

  1. During the serve or build, the index.html is served as the main HTML, so you also need to add this path in your content property in order for the Tailwind class checker to work properly and include the classes at runtime (after doing this, I no longer face the issue of class being removed on consecutive saves. Also, the classes were applied properly without saving .scss or .config file. So, the content value now becomes:
content: ["./src/**/*.{html,ts,js}", "./index.html"],
  1. In our project, we are using Angular Material and its styles were in conflict with the styles of Tailwind. So for this reason, we need to turn on the important flag in our config. Final config looks like:
/** @type {import('tailwindcss').Config} */
module.exports = {
  content: ["./src/**/*.{html,ts,js}", "./index.html"],   // <-------
  theme: {},
  plugins: [],
  important: true // <-------
}

Pro tip: Don't forget to check the dist folder's generated style.css when you create your production build. Look for Tailwind classes are included because it's better to be safe than sorry!

I hope I could save someone's hours of headache... ;)

Clothilde answered 12/7 at 9:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.