Sub topic 14
Troubleshooting common problems
This chapter assumes you have followed the earlier chapters. You have a Vite project with tailwindcss and @tailwindcss/vite installed, the plugin registered in vite.config.ts, and @import "tailwindcss"; in a CSS file that your app loads. You should be comfortable reading terminal output and browser DevTools.
Most setup failures come from one of four places: a missing link in the chain (plugin, CSS import, stylesheet import), a class name that Tailwind cannot see, a leftover v3 configuration, or an unsupported environment. The sections below work through each, starting with a way to find out which link is broken.
Find the broken link first
Tailwind only produces CSS when every step in this chain works:
- The plugin is installed and registered in the Vite config.
- A CSS file contains
@import "tailwindcss";. - The app imports that CSS file.
- The class names appear in a file Tailwind scans.
A fault at any step looks the same on screen: unstyled content. Test the steps in order instead of guessing.
A useful first check is the Network tab in DevTools. Reload the page and look for your CSS file. If it is missing, the stylesheet is never loaded (step 3). If it is present and large, open it and search for a utility such as .text-3xl. If the utility is absent, Tailwind did not see the class (step 4). If the file contains the raw text @import "tailwindcss", the plugin is not processing it (steps 1 or 2).
The plugin is not registered or not running
Symptom: The CSS file is served, but it contains the literal line @import "tailwindcss";, or the page has no Tailwind styles at all.
Cause: Vite does not know how to process the Tailwind directives. Check vite.config.ts against this working version:
import { defineConfig } from 'vite'
import tailwindcss from '@tailwindcss/vite'
export default defineConfig({
plugins: [
tailwindcss(),
],
})Common mistakes:
- The import is present, but
tailwindcss()is not in thepluginsarray. - You wrote
tailwindcsswithout calling it. The plugin is a function and must be invoked. - You edited a different config file, for example
vite.config.jswhilevite.config.tsalso exists. Vite picks one of them and ignores the other. - You imported
tailwindcssfrom thetailwindcsspackage instead of@tailwindcss/vite. Thetailwindcsspackage is the engine and does not export a Vite plugin.
Vite reads its config only at startup. After any change to the config file, stop the dev server and start it again.
The stylesheet is never loaded
Symptom: The plugin is registered and the CSS file has the correct import, yet nothing changes in the browser.
Cause: Vite only processes files that something imports. A CSS file that sits in src/ but is not referenced is ignored. In a plain JavaScript project, the entry file must import it:
import './style.css'
document.querySelector('#app').innerHTML = `
<h1 class="text-3xl font-bold underline text-blue-600">Hello Tailwind</h1>
`Check three details:
- The path is correct and the case matches. A path that works on macOS or Windows can fail on Linux, where file names are case-sensitive.
- The file you import is the one that holds
@import "tailwindcss";. Projects created from a template often include a second stylesheet such asApp.cssorindex.css. - If your page is served from an
index.htmlthat links a stylesheet with a<link>tag, the link must point to the CSS file with the Tailwind import, and the plugin must still be registered.
Classes do not generate
Symptom: The stylesheet loads and Tailwind's base styles apply (headings lose their default size, for example), but specific utilities are missing.
Cause: Tailwind v4 generates CSS only for class names it finds in your source files. It scans automatically, so no content array is needed, but detection has rules:
- It finds class names as complete, unbroken strings. It does not run your code.
- It ignores files listed in
.gitignore, binary files, CSS files, and lock files. - It does not scan
node_modulesby default, because that directory is normally gitignored.
Dynamically built class names
This is the most common cause of missing utilities. Tailwind reads text, so a name assembled at runtime is invisible to it:
// Broken: "text-red-600" never appears as a whole string
const color = 'red'
el.className = `text-${color}-600`
// Works: the full class names are written out
const colors = {
red: 'text-red-600',
green: 'text-green-600',
}
el.className = colors[color]Keep complete class names in your source, in a lookup object like the one above or in conditional expressions.
Classes in packages or ignored folders
If the classes live in a dependency, such as a shared UI library in node_modules, or in a gitignored folder, register the directory with @source:
@import "tailwindcss";
@source "../node_modules/@my-company/ui-lib";The path is resolved relative to the CSS file that contains the directive, not to the project root. A wrong number of ../ segments is a frequent cause of this fix not working.
Verify what is being generated
Search the served CSS for the missing class. If it is absent, copy the exact class string into a file under src/ and see whether it appears after a reload. If it does, the original source was not being scanned or the name was built dynamically.
Leftover v3 configuration
Many tutorials, templates, and editor snippets still describe v3. Mixing the two produces errors or silent failures.
| v3 habit | v4 equivalent | What goes wrong if you keep it |
|---|---|---|
| `@tailwind base; @tailwind components; @tailwind utilities;` | `@import "tailwindcss";` | The old directives do not produce the v4 output, so styles are missing or incomplete. |
| `tailwind.config.js` with `content` | Automatic detection, plus `@source` | The config file is not loaded automatically, so your customizations have no effect. |
| `theme.extend.colors` in JavaScript | `@theme { --color-brand: ... }` | Custom colors do not exist, so `bg-brand` generates nothing. |
| `tailwindcss` and `autoprefixer` in PostCSS | `@tailwindcss/vite` | The PostCSS setup can run next to the Vite plugin and cause duplicate or conflicting processing. |
If you are starting a fresh project, delete tailwind.config.js and postcss.config.js if a template created them, and remove the @tailwind directives. Move design tokens into @theme:
@import "tailwindcss";
@theme {
--color-brand: #3b82f6;
--font-display: "Georgia", serif;
}After you restart the server, bg-brand, text-brand, and font-display should all work. If they do not, check that the variable names use the right namespace prefix. --color-* creates color utilities, and --font-* creates font family utilities. A variable named --brand creates no utility.
A project upgraded from v3 can also hit trouble if it still has postcss-import, autoprefixer, or tailwindcss listed as a PostCSS plugin. Tailwind v4 handles imports and vendor prefixes itself.
PostCSS and Vite plugin conflicts
If you must use PostCSS, the setup is different, and it replaces the Vite plugin. Use one or the other:
export default {
plugins: {
"@tailwindcss/postcss": {},
},
}Errors such as "It looks like you're trying to use tailwindcss directly as a PostCSS plugin" mean that a config still lists tailwindcss itself as the plugin. In v4 the PostCSS plugin lives in the separate @tailwindcss/postcss package. Install it, and change the plugin name.
Install and environment errors
| Symptom | Likely cause | Fix |
|---|---|---|
| `Cannot find module '@tailwindcss/vite'` | Package not installed, or installed in a different folder | Run `npm install tailwindcss @tailwindcss/vite` in the folder that holds `package.json` for the Vite app. |
| Peer dependency error mentioning Vite | The installed Vite version is older than the plugin supports | Check the plugin's peer range with `npm info @tailwindcss/vite peerDependencies` and upgrade Vite. |
| Node version or `ERR_REQUIRE_ESM` error | Node.js is too old for the tools | Upgrade Node.js to a current LTS release. |
| Config file fails to load with an ESM error | A `require`-style config in a project that uses `"type": "module"` | Use `import` syntax in `vite.config.ts`. |
Run npm ls tailwindcss @tailwindcss/vite vite to confirm what is actually installed. Two copies of tailwindcss at different versions, usually from a stale monorepo workspace, can cause confusing behavior. Remove node_modules and the lock file for the affected package and reinstall if the tree looks wrong.
Browser appearance problems
If utilities generate correctly but look broken in a specific browser, check its version. Tailwind v4 relies on modern CSS features, including cascade layers, @property, and color-mix(). It targets recent releases of Safari, Chrome, and Firefox. Older browsers can drop whole rules, so colors or shadows look wrong while layout works. If you need to support older browsers, stay on Tailwind v3.4 instead.
Development works, production does not
The production build runs through the same plugin, so most problems appear in both. Differences you may see:
- Classes present in dev but missing after
npm run build. Usually the class is built dynamically and only appeared to work because of caching. Fix it as described above. - The deployed site returns 404 for the CSS file. Check the
baseoption invite.config.tsif you deploy under a sub-path.
Exercise
A page loads style.css correctly, and base styles apply. The class bg-brand does nothing, although you defined --brand: #3b82f6; inside @theme. What is wrong and how do you fix it?
Show answer
The variable is in the wrong namespace. Tailwind builds color utilities only from variables that start with --color-. Rename it to --color-brand: #3b82f6;, restart the dev server if needed, and bg-brand and text-brand will generate.
Exercise
Your component builds a class with ` bg-${tone}-500 where tone is blue or green`. In the browser, neither background appears. Why, and what is the fix?
Show answer
Tailwind scans source text and never runs the code, so it never sees the complete strings bg-blue-500 or bg-green-500. Write the full names, for example in an object such as { blue: 'bg-blue-500', green: 'bg-green-500' }, and look up the value by key.
Exercise
The served CSS file contains the literal text @import "tailwindcss";. Name two things to check.
Show answer
First, confirm tailwindcss() from @tailwindcss/vite is called inside the plugins array of the Vite config file that is actually in use. Second, restart the dev server, because Vite reads the config only at startup. A third possible check is that you did not import tailwindcss from the wrong package.