Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Next.js and React

Vite cannot resolve @tailwindcss/vite after adding Tailwind CSS

ErrorFailed 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.

  • Applies to Vite 7, Tailwind CSS 4, Node.js 22
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Ask npm whether both packages are installed in this project.

    npm ls tailwindcss @tailwindcss/vite
  2. 2Match what you see, then jump to its fix

    1. 1npm ls prints (empty) or missing for @tailwindcss/viteThe packages are not installed in this projectFix
    2. 2The install works but classes do nothingThe plugin is not registered in the Vite configFix
    3. 3No error, but utility classes produce no stylesTailwind is not imported in the CSSFix

What does the error look like?

  • Failed to resolve "@tailwindcss/vite"
  • Cannot find package '@tailwindcss/vite' imported from vite.config
  • Tailwind 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.json

2Fix

Install both packages.

npm install tailwindcss @tailwindcss/vite

3Verify

npm ls lists both with a version.

npm ls tailwindcss @tailwindcss/vite

Confirmed by tailwindcss.com

Did this fix it?

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.ts

2Fix

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 dev

Confirmed by tailwindcss.com

Did this fix it?

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/*.css

2Fix

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 dev

Confirmed by tailwindcss.com

Did this fix it?

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 fix

Web 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 fix

Web 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 fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.