shadcn/ui: Component Not Found After Install โ How to Fix It
Module not found: Can't resolve '@/components/ui/button'
This error means your bundler canโt find the shadcn/ui component file. The component was either not installed correctly, installed to the wrong directory, or your path alias isnโt configured properly.
What causes this
shadcn/ui doesnโt install components into node_modules โ it copies component source files directly into your project. The CLI uses a components.json config file to determine where to put them. If the path alias (@/) doesnโt resolve to the right directory, or the component file wasnโt created, you get this error.
Common triggers:
- The
@/*path alias intsconfig.jsondoesnโt match your project structure components.jsonpoints to the wrong directory- The
npx shadcn-ui addcommand failed silently or was interrupted - You moved your
src/directory after runningshadcn-ui init
Fix 1: Check your path alias in tsconfig.json
The @/* alias must point to the directory that contains your components/ folder:
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"]
}
}
}
If your project doesnโt use a src/ directory, adjust accordingly:
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/*": ["./*"]
}
}
}
For Next.js, also make sure next.config.js isnโt overriding the webpack alias resolution.
Fix 2: Check components.json
The components.json file in your project root tells the shadcn CLI where to install components:
{
"style": "default",
"tailwind": {
"config": "tailwind.config.js",
"css": "src/app/globals.css"
},
"aliases": {
"components": "@/components",
"utils": "@/lib/utils"
}
}
If aliases.components is @/components, the CLI will create files at src/components/ui/ (assuming @ maps to src). Make sure this matches your actual project structure.
Fix 3: Reinstall the component
If the file simply doesnโt exist, re-run the add command:
npx shadcn-ui@latest add button
Verify the file was created:
ls src/components/ui/button.tsx
If the CLI asks you to overwrite, say yes. If it errors out, check that components.json exists in your project root โ run npx shadcn-ui@latest init if it doesnโt.
Fix 4: Check the utils dependency
Most shadcn/ui components import a cn() utility function. If that file is missing, the component itself will fail to resolve:
# Check if the utils file exists
ls src/lib/utils.ts
If itโs missing, create it:
// src/lib/utils.ts
import { type ClassValue, clsx } from "clsx";
import { twMerge } from "tailwind-merge";
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
}
And make sure the dependencies are installed:
npm install clsx tailwind-merge
Related resources
How to prevent it
- Run
npx shadcn-ui@latest initbefore adding any components. This createscomponents.jsonwith the correct paths for your project. - Donโt manually move component files after installation โ update
components.jsonand reinstall instead. - If youโre using a monorepo, make sure the path alias resolves correctly from the package where youโre importing the component, not just from the root.
Related: React Interview Questions