shadcn/uiNext.jsError Fix2026 Updated

shadcn/ui Not Working in Next.js— Components Unstyled [Fixed 2026]

Also covers: shadcn init · Tailwind CSS config · CSS variables · cn() utility · Tailwind v4 · production styles

January 20267 min readshadcn/ui · Next.js 14/15 · Tailwind CSS

⚡ The Symptom

Error
// Components render but have NO styles — plain HTML appearance
// OR:
Module not found: Can't resolve '@/lib/utils'
// OR:
Cannot find module '@/components/ui/button'

✅ Correct setup sequence

Terminal
# 1. Init shadcn (creates components.json, updates tailwind config, globals.css)
npx shadcn@latest init

# 2. Add components as needed
npx shadcn@latest add button
npx shadcn@latest add dialog input card

Why shadcn/ui Components Appear Unstyled

shadcn/ui relies on three things to render correctly: Tailwind CSS scanning the component files, CSS custom properties (variables) in your globals.css, and the cn() utility in lib/utils.ts . If any of these is missing or misconfigured, components render as plain unstyled HTML.

The npx shadcn@latest init command sets up all three automatically. If you manually copied components without running init, you need to add the configuration manually.

1

Run the Correct shadcn Init Command

Start here — init handles all configuration
3 min
Complete shadcn setup for Next.js
# For Tailwind CSS v3 (most common as of 2026):
npx shadcn@latest init

# For Tailwind CSS v4 (if you're using v4):
npx shadcn@canary init

# The init wizard asks:
# ✓ Which style? → Default (or New York)
# ✓ Which base color? → Slate (or your preference)
# ✓ Use CSS variables for colors? → Yes
# ✓ Where is globals.css? → app/globals.css
# ✓ tailwind.config.ts path → tailwind.config.ts
# ✓ Components alias → @/components
# ✓ Utils alias → @/lib/utils

# After init, the wizard creates:
# - components.json (config)
# - lib/utils.ts (cn() utility)
# - Updates tailwind.config.ts (content paths + colors)
# - Updates app/globals.css (CSS variables)
2

Fix Tailwind CSS Configuration

Styles present in dev but missing in prod
3 min

Tailwind must be configured to scan the components/ui directory. Without this, component classes are purged in production builds.

tailwind.config.ts — correct content paths
import type { Config } from "tailwindcss"

const config: Config = {
  darkMode: ["class"],
  content: [
    "./pages/**/*.{ts,tsx}",
    "./components/**/*.{ts,tsx}",    // ← includes components/ui/
    "./app/**/*.{ts,tsx}",
    "./src/**/*.{ts,tsx}",
  ],
  theme: {
    container: {
      center: true,
      padding: "2rem",
      screens: { "2xl": "1400px" },
    },
    extend: {
      colors: {
        border: "hsl(var(--border))",
        input: "hsl(var(--input))",
        ring: "hsl(var(--ring))",
        background: "hsl(var(--background))",
        foreground: "hsl(var(--foreground))",
        primary: {
          DEFAULT: "hsl(var(--primary))",
          foreground: "hsl(var(--primary-foreground))",
        },
        // ... more color tokens
      },
    },
  },
  plugins: [require("tailwindcss-animate")],
}

export default config
3

Add CSS Variables to globals.css

Components render but colors are wrong or missing
3 min

shadcn/ui components use CSS custom properties for all colors. Without these variables, all color utilities resolve to transparent or nothing.

app/globals.css — required CSS variables
@tailwind base;
@tailwind components;
@tailwind utilities;

@layer base {
  :root {
    --background: 0 0% 100%;
    --foreground: 222.2 84% 4.9%;
    --card: 0 0% 100%;
    --card-foreground: 222.2 84% 4.9%;
    --popover: 0 0% 100%;
    --popover-foreground: 222.2 84% 4.9%;
    --primary: 222.2 47.4% 11.2%;
    --primary-foreground: 210 40% 98%;
    --secondary: 210 40% 96.1%;
    --secondary-foreground: 222.2 47.4% 11.2%;
    --muted: 210 40% 96.1%;
    --muted-foreground: 215.4 16.3% 46.9%;
    --accent: 210 40% 96.1%;
    --accent-foreground: 222.2 47.4% 11.2%;
    --destructive: 0 84.2% 60.2%;
    --destructive-foreground: 210 40% 98%;
    --border: 214.3 31.8% 91.4%;
    --input: 214.3 31.8% 91.4%;
    --ring: 222.2 84% 4.9%;
    --radius: 0.5rem;
  }

  .dark {
    --background: 222.2 84% 4.9%;
    --foreground: 210 40% 98%;
    /* ... dark mode variables */
  }
}

@layer base {
  * { @apply border-border; }
  body { @apply bg-background text-foreground; }
}
4

Fix the cn() Utility Import Path

Module not found '@/lib/utils'
2 min

All shadcn components import from @/lib/utils . Create this file if it's missing.

lib/utils.ts — create this file
import { type ClassValue, clsx } from "clsx"
import { twMerge } from "tailwind-merge"

export function cn(...inputs: ClassValue[]) {
  return twMerge(clsx(inputs))
}

# Install the dependencies if missing:
npm install clsx tailwind-merge
tsconfig.json — verify the @ path alias
{
  "compilerOptions": {
    "paths": {
      "@/*": ["./*"]    // ← maps @/ to project root
    }
  }
}

shadcn expects the @/* alias to map to your project root. If your app is inside a src/ directory, the alias should be @/*: ['./src/*'] instead.

5

Fix Components Not Styled in Production

Works in dev but unstyled after build
3 min

If components look correct in development but lose styles after next build, Tailwind is purging classes it can't find in the scanned files. Usually the content paths in tailwind.config.ts are missing the components directory.

Debug — check which classes are being purged
# Build and check the CSS output size
next build

# If styles/globals.css is very small (< 10KB), Tailwind is purging too aggressively

# Fix — ensure components/ui is in content paths
content: [
  "./app/**/*.{ts,tsx}",
  "./components/**/*.{ts,tsx}",   // ← must include this
  "./pages/**/*.{ts,tsx}",
]

# If using src/ layout:
content: [
  "./src/app/**/*.{ts,tsx}",
  "./src/components/**/*.{ts,tsx}",
]

# Also ensure tailwindcss-animate is installed
npm install tailwindcss-animate

Prevention

Frequently Asked Questions

Why do shadcn/ui components appear completely unstyled?+
shadcn/ui components use Tailwind CSS classes. If the components look unstyled, either Tailwind is not configured to scan the component files, the CSS variables in globals.css are missing, or the shadcn init command was not run correctly. Check all three.
Do I need to install shadcn/ui as a package?+
No. shadcn/ui is not installed as an npm package. You run npx shadcn@latest add button (or any component) and it copies the component source code directly into your project — typically into components/ui/. You own the code and can modify it freely.
What is the cn() utility in shadcn/ui?+
cn() is a helper that merges Tailwind CSS classes intelligently using clsx and tailwind-merge. It handles conditional classes and resolves conflicts between Tailwind utility classes. It is defined in lib/utils.ts and imported by all shadcn components.
Why does shadcn/ui not work with Tailwind CSS v4?+
shadcn/ui has a Tailwind v4 compatible version. Run npx shadcn@canary init for the Tailwind v4 setup. The configuration is different — instead of tailwind.config.ts, styles are configured in CSS using @import and @theme directives.
Can I use shadcn/ui without Next.js?+
Yes. shadcn/ui works with any React framework — Vite, Remix, Astro, Laravel. Run npx shadcn@latest init and select your framework. The components are framework-agnostic React components using Radix UI primitives and Tailwind CSS.
How do I add a new shadcn/ui component to my project?+
Run npx shadcn@latest add component-name — for example, npx shadcn@latest add button or npx shadcn@latest add dialog. This copies the component into your components/ui/ directory. You can then import it from '@/components/ui/button'.

Need Expert Help?

We Build Next.js Apps with shadcn/ui

Softplix engineers build production Next.js applications with shadcn/ui, Tailwind CSS, and strict TypeScript. Need a UI system set up correctly? Let us help.

Talk to an Engineer