[bug]: `shadcn init` CLI defaults to npm when using Bun, causing unnecessary conflicts and prompts
Describe the bug
Description:
When I run shadcn init with Bun, the CLI always defaults to using npm, which leads to the following issues:
- Unnecessary prompts: It asks me to use the
--forceflag, which is not required for Bun. - Lock file conflicts: It creates a
package-lock.json, leading to duplicate lock files (bun.lockbandpackage-lock.json), which is undesirable in Bun-based projects.
Expected Behavior:
The shadcn CLI should detect and respect the package manager being used (in this case, Bun) without defaulting to npm. It should avoid unnecessary prompts and not generate a package-lock.json in Bun-based projects.
Additional Context:
- I tested this behavior with both
@latestand@canaryversions of theshadcnCLI (the latter for testing with Tailwind CSS v4). - My environment is fully set up for Bun, and I can confirm that other tools correctly recognize Bun as the package manager.
Let me know if you need more details or additional logs to debug this issue. Thank you! 😊
Affected component/components
CLI
How to reproduce
- Initialize a Bun-based project.
- Run any of the following commands:
bunx shadcn initbun x shadcn initbunx --bun shadcn initbun x --bun shadcn init
- Observe that the CLI defaults to npm instead of Bun.
Codesandbox/StackBlitz link
No response
Logs
System Info
# System Details Report
---
## Report details
- **Date generated:** 2025-02-07 09:19:48
## Hardware Information:
- **Hardware Model:** Gigabyte Technology Co., Ltd. X570S AORUS ELITE
- **Memory:** 64.0 GiB
- **Processor:** AMD Ryzen™ 9 5900X × 24
- **Graphics:** AMD Radeon™ RX 6900 XT
- **Disk Capacity:** 1.5 TB
## Software Information:
- **Firmware Version:** F9d
- **OS Name:** Fedora Linux 41 (Workstation Edition)
- **OS Build:** (null)
- **OS Type:** 64-bit
- **GNOME Version:** 47
- **Windowing System:** Wayland
- **Kernel Version:** Linux 6.12.11-200.fc41.x86_64
Before submitting
- [x] I've made research efforts and searched the documentation
- [x] I've searched for existing issues
I have the same problem, so working with bun is not possible at the moment.
The shadcn docs still say that it should work with bun without --legacy-peer-deps or --force. Then it creates a package.json.lock (because it's using npm).
This also happens when trying to add components.
"react": "^19.0.0", "react-dom": "^19.0.0", "next": "15.1.6"
Please help to fix this.
Same issue here !
In Bun v1.2, we migrated from bun's binary bun.lockb to the text-based bun.lock as the default option for bun install (when a bun.lockb doesn't exist)
To detect bun install, tools must look for both bun.lock and bun.lockb. Maybe shadcn is only looking for bun.lockb to detect bun?
Edit: looks like this PR likely fixes this https://github.com/shadcn-ui/ui/pull/6152
Updating @antfu/ni to v0.23.2 indeed fixes the issue.
Until shadcn makes the update, the fix temporary fix is make shadcn local in your project.
- Add
"@antfu/ni": "^0.23.2"to resolutions in package.json - Add
"shadcn": "shadcn"to script bun install -D shadcn@canaryorbun install -D shadcn@latest- use
bun shadcn add
Ah, thank you! That temporary fix worked perfectly for me for now.
I deleted and reinstalled bun. And it works now.
As a quick fix: For me renaming bun.lock to bun.lockb also worked when using Nextjs 15, React 19 and shadcn.