shadcn-ui command not found error
Problem Statement
When attempting to use Shadcn UI commands in your terminal, you encounter an error similar to this:
npx shadcn-ui@latest add button
sh: line 1: shadcn-ui: command not found
This issue typically occurs when:
- Trying to add components like buttons using
shadcn-ui
commands - Initializing new projects with
npx shadcn-ui@latest init
- The terminal returns "command not found" despite having a working network connection
- The problem persists even after creating a new project from scratch
The root cause is a recent package naming change by Shadcn UI that affects how developers interact with their CLI.
Recommended Solution: Use Updated CLI Commands
Shadcn UI renamed their CLI package from shadcn-ui
to shadcn
in recent updates. Use these updated commands instead:
1. Initialize your project with the new CLI:
npx shadcn@latest init
This command will:
- Install required dependencies
- Configure
tailwind.config.js
- Add CSS variables to your application
2. Add components using the updated syntax:
npx shadcn@latest add button
3. For projects in a monorepo, specify the path:
npx shadcn@latest add button -c ./apps/www
Alternative Approaches
Install Shadcn as a Dependency
If the npx
method fails, install Shadcn as a project dependency:
npm install shadcn
npx shadcn@latest init
npx shadcn@latest add button
Global Installation
For frequent use across projects, install globally:
npm install -g shadcn
shadcn add button
Windows Subsystem for Linux (WSL) Fixes
WSL users encountering dependency issues can try:
npm i shadcn-ui
npm audit fix --force
npx shadcn-ui init
Best Practices
Always reference the official Shadcn CLI documentation for the most current commands and workflow changes.
Version-Specific Workarounds
While you can target older versions of the CLI:
npx shadcn-ui@0.8.0 init
This approach is not recommended as it uses outdated versions missing security patches and new features.
Why This Error Occurs
The "command not found" error specifically results from Shadcn's transition from:
- Old npm package:
shadcn-ui
- New npm package:
shadcn
The maintainers updated their CLI name without maintaining a redirect aliasing system, causing existing commands to break.
Verifying the Solution
Confirm the CLI works by running:
npx shadcn@latest --version
You should see version information without errors:
shadcn/1.0.0 darwin-x64 node-v18.17.1
Preventing Future Issues
To avoid similar problems:
- Regularly check framework documentation for updates
- Follow official Shadcn UI Twitter/GitHub accounts for announcements
- Use precise versioning (
@latest
ensures you get breaking changes) - Consider adding shadcn dependencies explicitly in
package.json