ui icon indicating copy to clipboard operation
ui copied to clipboard

[bug]: `shadcn init` CLI defaults to npm when using Bun, causing unnecessary conflicts and prompts

Open brielov opened this issue 10 months ago • 7 comments

Describe the bug

Description:

When I run shadcn init with Bun, the CLI always defaults to using npm, which leads to the following issues:

  1. Unnecessary prompts: It asks me to use the --force flag, which is not required for Bun.
  2. Lock file conflicts: It creates a package-lock.json, leading to duplicate lock files (bun.lockb and package-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 @latest and @canary versions of the shadcn CLI (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

  1. Initialize a Bun-based project.
  2. Run any of the following commands:
    • bunx shadcn init
    • bun x shadcn init
    • bunx --bun shadcn init
    • bun x --bun shadcn init
  3. 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

brielov avatar Feb 07 '25 12:02 brielov

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.

Image

kinglycodes avatar Feb 07 '25 16:02 kinglycodes

Same issue here !

Hervepoh avatar Feb 09 '25 10:02 Hervepoh

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

Jarred-Sumner avatar Feb 09 '25 11:02 Jarred-Sumner

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.

  1. Add "@antfu/ni": "^0.23.2" to resolutions in package.json
  2. Add "shadcn": "shadcn" to script
  3. bun install -D shadcn@canary or bun install -D shadcn@latest
  4. use bun shadcn add

fishefam avatar Feb 11 '25 02:02 fishefam

Ah, thank you! That temporary fix worked perfectly for me for now.

oscabriel avatar Feb 17 '25 22:02 oscabriel

I deleted and reinstalled bun. And it works now.

EngelbertTeh avatar Mar 06 '25 12:03 EngelbertTeh

As a quick fix: For me renaming bun.lock to bun.lockb also worked when using Nextjs 15, React 19 and shadcn.

kinglycodes avatar Mar 12 '25 18:03 kinglycodes