shadcn/ui setup fails in a Vite React project using Tailwind v4
shadcn init cannot resolve the @/ import aliasShort answer
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.
Fix it fast
1Find out which cause you have
Check that the three places the official Vite guide edits exist: tsconfig files, vite.config and the CSS entry.
grep -n "paths" tsconfig.json tsconfig.app.json grep -n "tailwindcss\|alias" vite.config.ts head -3 src/index.css2Match what you see, then jump to its fix
- 1
shadcn init reports it cannot resolve the aliasThe @/* alias is missing from tsconfig.jsonFix - 2
Editor underlines the @/ imports even though the build worksThe alias is missing from tsconfig.app.jsonFix - 3
Build fails to resolve @/ imports, or path and __dirname are unknown to TypeScriptvite.config.ts has no alias, or Node types are missingFix - 4
Classes do nothing; the CSS still uses v3 directives or a PostCSS setupTailwind v4 is not wired the v4 wayFix
- 1
What does the error look like?
shadcn init cannot resolve the @/ import aliasImports from @/components/ui do not resolve in the editor or the buildTailwind classes have no effect after shadcn add
Cause 1 of 4
The @/* alias is missing from tsconfig.json
1Check
The shadcn Vite guide adds baseUrl and paths to compilerOptions in tsconfig.json.
grep -n "paths\|baseUrl" tsconfig.json2Fix
Add the alias to the root tsconfig.json.
{
"files": [],
"references": [
{ "path": "./tsconfig.app.json" },
{ "path": "./tsconfig.node.json" }
],
"compilerOptions": {
"baseUrl": ".",
"paths": { "@/*": ["./src/*"] }
}
}3Verify
Run the init again.
npx shadcn@latest initConfirmed by ui.shadcn.com
Cause 2 of 4
The alias is missing from tsconfig.app.json
1Check
The guide also adds the same alias to tsconfig.app.json so the editor can resolve imports.
grep -n "paths" tsconfig.app.json2Fix
Add baseUrl and paths to the compilerOptions of tsconfig.app.json.
"compilerOptions": {
"baseUrl": ".",
"paths": { "@/*": ["./src/*"] }
}3Verify
Restart the TypeScript server and open a file that imports from @/.
npx tsc -p tsconfig.app.json --noEmitConfirmed by ui.shadcn.com
Cause 3 of 4
vite.config.ts has no alias, or Node types are missing
1Check
The guide installs @types/node so Vite can resolve the alias, and sets resolve.alias in vite.config.ts.
grep -n "@types/node" package.json2Fix
Install the types and register the alias and the Tailwind plugin.
npm install -D @types/node
// vite.config.ts
import path from "path"
import tailwindcss from "@tailwindcss/vite"
import react from "@vitejs/plugin-react"
import { defineConfig } from "vite"
export default defineConfig({
plugins: [react(), tailwindcss()],
resolve: { alias: { "@": path.resolve(__dirname, "./src") } },
})3Verify
Build the project.
npm run buildConfirmed by ui.shadcn.com
Cause 4 of 4
Tailwind v4 is not wired the v4 way
1Check
In the guide, Tailwind is installed with the @tailwindcss/vite plugin and src/index.css contains one line, @import "tailwindcss".
cat src/index.css | head -52Fix
Install the plugin and replace the CSS contents with the single import.
npm install tailwindcss @tailwindcss/vite
/* src/index.css */
@import "tailwindcss";3Verify
Add a Tailwind class to a component and check it is applied.
npm run devConfirmed by ui.shadcn.com
How do I stop it coming back?
- Follow the shadcn Vite guide in order: Tailwind, CSS, both tsconfig files, vite.config, then init.
- Run init only on a project that already builds.
- Keep one alias definition in all three places.
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:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- WorkforceA field app, an admin console and a self-hosted Node.js server for push and reconciliation.
Related fixes
Web 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
React shows Attempted import error when importing a component or function
Attempted import error:
The build found the file but not the name you asked for.
2 causes, each with a fixWeb apps
AxiosError Network Error with code ERR_NETWORK in a React app
Network Error
ERR_NETWORK means the request produced no readable response.
4 causes, each with a fixWeb apps
Axios get works with a URL string but ignores the object passed as the second argument
The server log shows a GET with no query string
axios.get takes a URL and an optional config object.
3 causes, each with a fixWeb apps
Can't resolve '../axios' in a React project
Module not found: Error: Can't resolve '../axios'
A path that starts with ./ or ../ is a file path, not the axios package.
3 causes, each with a fixWeb apps
Axios returns 401 from a React app but the login works elsewhere
Error: Request failed with status code 401
A 401 means the server received the request without valid credentials.
3 causes, each with a fix