Vite cannot resolve @tailwindcss/vite after adding Tailwind CSS
Failed to resolve "@tailwindcss/vite"Short answer
The error means the package is not installed in this project, or the config imports it from the wrong place. Install tailwindcss and @tailwindcss/vite together, add the plugin to vite.config, and import tailwindcss once in your main CSS file.
Fix it fast
1Find out which cause you have
Ask npm whether both packages are installed in this project.
npm ls tailwindcss @tailwindcss/vite2Match what you see, then jump to its fix
What does the error look like?
Failed to resolve "@tailwindcss/vite"Cannot find package '@tailwindcss/vite' imported from vite.configTailwind classes have no effect after setup
Cause 1 of 3
The packages are not installed in this project
1Check
The plugin ships as its own package next to tailwindcss, so a project upgraded to a newer Vite does not have it until you add it.
grep -n tailwind package.json2Fix
Install both packages.
npm install tailwindcss @tailwindcss/vite3Verify
npm ls lists both with a version.
npm ls tailwindcss @tailwindcss/viteConfirmed by tailwindcss.com
Cause 2 of 3
The plugin is not registered in the Vite config
1Check
Open the config and look for the import and the plugins entry.
cat vite.config.ts2Fix
Import the plugin and add it to plugins.
import { defineConfig } from 'vite'
import tailwindcss from '@tailwindcss/vite'
export default defineConfig({
plugins: [
tailwindcss(),
],
})3Verify
Start the dev server without errors.
npm run devConfirmed by tailwindcss.com
Cause 3 of 3
Tailwind is not imported in the CSS
1Check
The main CSS file must import tailwindcss, and that file must be loaded by the app.
grep -rn 'tailwindcss' src/*.css2Fix
Add the import to the CSS file the app loads.
@import "tailwindcss";3Verify
Use a utility class such as text-3xl font-bold in a component and reload.
npm run devConfirmed by tailwindcss.com
How do I stop it coming back?
- Follow the install steps in the order the Tailwind guide gives them when upgrading an old project.
- Commit the lockfile so a fresh clone installs the same packages.
- Remove old PostCSS or config files from an earlier Tailwind setup only after the new one works.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Web apps
Next.js fails with Cannot find module 'tailwindcss'
Error: Cannot find module 'tailwindcss'
Next.js loads Tailwind through PostCSS, so the error means the package named in postcss.config is not installed where the build runs.
3 causes, each with a fixWeb apps
shadcn/ui setup fails in a Vite React project using Tailwind v4
Imports from @/components/ui do not resolve in the editor or the build
shadcn init needs three things in a Vite project: Tailwind v4 installed with the @tailwindcss/vite plugin and a single @import "tailwindcss" line in your CSS, the @/* path alias in both tsconfig.json and tsconfig.app.json, and the same alias in vite.config.ts, with @types/node installed so path resolves.
4 causes, each with a fixWeb apps
Tailwind CSS 4 build fails on @apply in a Next.js project
Cannot apply unknown utility class
Tailwind 4 only knows its utilities in a stylesheet that imports Tailwind.
2 causes, each with a fixWeb apps
A custom Tailwind width or height class has no effect
The same width written in plain CSS works
Tailwind only creates CSS for class names it finds as complete strings in files it scans.
3 causes, each with a fixWeb apps
Tailwind build says the dark: class does not exist
dark: utilities work in markup but the build fails where @apply uses them in a separate CSS file
The build error means the CSS file being compiled cannot see your dark variant.
3 causes, each with a fixWeb apps
Build fails because a tool still runs PostCSS 7 and Tailwind needs 8
Error: PostCSS plugin tailwindcss requires PostCSS 8.
Tailwind CSS 2 and later depend on PostCSS 8.
2 causes, each with a fix