shadcn/ui path aliases (@/) not working: tsconfig and Vite fixes
Fix Failed to resolve import "@/components/ui/..." in shadcn/ui: match tsconfig.json, tsconfig.app.json, vite.config.ts resolve.alias, and components.json.
- shadcn 4.23.0
- Tailwind CSS 4.3.5
- Vite 8
- React 19.3
If npx shadcn@latest init complains about missing import aliases or Vite throws Failed to resolve import "@/components/ui/button", TypeScript and your bundler disagree on what @/ points to. Fixing it takes matching tsconfig.json, vite.config.ts (for Vite) and components.json.
Three places that must match
Step 1: Add baseUrl and paths in tsconfig.json (and tsconfig.app.json)
Modern Vite templates split config into
tsconfig.jsonandtsconfig.app.json. The shadcn CLI reads the roottsconfig.json, while TypeScript/IDE checks readtsconfig.app.json— addpathsto both:tsconfig.jsonJSON { "compilerOptions": { "baseUrl": ".", "paths": { "@/*": ["./src/*"] } }}Step 2: Mirror the alias in vite.config.ts
TypeScript paths only affect type-checking — Vite does not read them automatically. Add
resolve.aliasinvite.config.ts:vite.config.tsTypeScript import path from "node:path";import { defineConfig } from "vite";import react from "@vitejs/plugin-react";import tailwindcss from "@tailwindcss/vite"; export default defineConfig({ plugins: [react(), tailwindcss()], resolve: { alias: { "@": path.resolve(__dirname, "./src"), }, },});Step 3: Check aliases in components.json
Make sure
components.jsonuses the same@/prefix so futurenpx shadcn@latest addcommands write matching imports:components.jsonJSON { "aliases": { "components": "@/components", "utils": "@/lib/utils", "ui": "@/components/ui", "lib": "@/lib", "hooks": "@/hooks" }}
Questions
Do I need resolve.alias in Next.js or Astro?
No. Both Next.js and Astro read compilerOptions.paths directly from tsconfig.json. Only Vite needs the extra resolve.alias block (or the vite-tsconfig-paths plugin).
Why does my monorepo still fail to resolve @/lib/utils?
Check whether the component was installed into a shared package whose own tsconfig.json has a different baseUrl. Either use a package name alias (@acme/ui/lib/utils) in components.json or keep components.json inside the app directory.
Related articles
- Tailwind CSS v4Tailwind v4 with Vite not working: plugin and CSS fixesFix Tailwind CSS v4 in Vite, React and Astro: register @tailwindcss/vite, remove leftover postcss.config.js, import tailwindcss, and configure @source.
- shadcn/uishadcn/ui not working with Tailwind v4: six causes and fixesUnstyled or transparent shadcn components on Tailwind v4 come from v3 leftovers: the old PostCSS plugin, @tailwind directives, hsl() wrappers, missing imports.
- shadcn/uiInstall components from a shadcn registry (npx shadcn add @namespace)Install by URL with no setup, or name a registry in components.json and install by namespace. Private registries read their key from .env.local.
Still stuck? We answer every message ourselves. Write to us