Skip to content

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.

Updated 3 December 2026Tested with
  • 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

  1. Step 1: Add baseUrl and paths in tsconfig.json (and tsconfig.app.json)

    Modern Vite templates split config into tsconfig.json and tsconfig.app.json. The shadcn CLI reads the root tsconfig.json, while TypeScript/IDE checks read tsconfig.app.json — add paths to both:

    tsconfig.jsonJSON
    {  "compilerOptions": {    "baseUrl": ".",    "paths": {      "@/*": ["./src/*"]    }  }}
  2. Step 2: Mirror the alias in vite.config.ts

    TypeScript paths only affect type-checking — Vite does not read them automatically. Add resolve.alias in vite.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"),    },  },});
  3. Step 3: Check aliases in components.json

    Make sure components.json uses the same @/ prefix so future npx shadcn@latest add commands 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.

Was this page helpful?

Still stuck? We answer every message ourselves. Write to us

Building with shadcn/ui and Tailwind CSS v4?

Install 188 free blocks and components with the shadcn CLI (no account), preview them in your own brand in Studio, or get all 1,570 blocks and every theme in UI Pro (€199 once).

Use it with

This page is built from UI Pro parts: the docs article block (docs-quernly) with the code, terminal, install command, steps, contents and feedback components, included in UI Pro.