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
⚡ The Symptom
// 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
# 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 cardWhy 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.
Run the Correct shadcn Init Command
Start here — init handles all configuration# 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)Fix Tailwind CSS Configuration
Styles present in dev but missing in prodTailwind must be configured to scan the components/ui directory. Without this, component classes are purged in production builds.
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 configAdd CSS Variables to globals.css
Components render but colors are wrong or missingshadcn/ui components use CSS custom properties for all colors. Without these variables, all color utilities resolve to transparent or nothing.
@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; }
}Fix the cn() Utility Import Path
Module not found '@/lib/utils'All shadcn components import from @/lib/utils . Create this file if it's missing.
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{
"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.
Fix Components Not Styled in Production
Works in dev but unstyled after buildIf 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.
# 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-animatePrevention
- Always run npx shadcn@latest init first — never manually copy component files without running init
- Verify the content paths in tailwind.config.ts include ./components/**/*.{ts,tsx}
- Check globals.css has the @layer base block with all CSS variables after running init
- Install clsx and tailwind-merge — they are required by the cn() utility
- Verify tsconfig.json has the @/* path alias pointing to your project root
- After adding a new component, import it from @/components/ui/button (not a node_modules path)
Frequently Asked Questions
Why do shadcn/ui components appear completely unstyled?+−
Do I need to install shadcn/ui as a package?+−
What is the cn() utility in shadcn/ui?+−
Why does shadcn/ui not work with Tailwind CSS v4?+−
Can I use shadcn/ui without Next.js?+−
How do I add a new shadcn/ui component to my project?+−
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