Skip to content

fix: monorepo templates ignore the user's package manager#9962

Merged
shadcn merged 5 commits intoshadcn-ui:mainfrom
devinscodebase:fix/monorepo-package-manager-detection
Mar 13, 2026
Merged

fix: monorepo templates ignore the user's package manager#9962
shadcn merged 5 commits intoshadcn-ui:mainfrom
devinscodebase:fix/monorepo-package-manager-detection

Conversation

@devinscodebase
Copy link
Copy Markdown
Contributor

Fixes #7695

All monorepo templates hardcode packageManager: "pnpm" which overrides
getPackageManager() entirely. Running bunx --bun shadcn init --monorepo
still shells out to pnpm install, Corepack tries to kick in, and Bun
crashes on process.mainModule = void 0 (readonly in Bun's runtime).

Repro:

bunx --bun shadcn@latest init --template start --monorepo

TypeError: Attempted to assign to readonly property.
  at runVersion (corepack.cjs:22426:3)

This removes the hardcoded overrides and lets detection work. Since the
templates on disk are pnpm-structured, the scaffold step now converts
them after cloning when a different PM is detected:

  • strips "packageManager" from package.json (stops Corepack)
  • moves workspace globs from pnpm-workspace.yaml into package.json "workspaces"
  • removes pnpm-lock.yaml
  • rewrites workspace:* to "*" for npm (bun/yarn handle it natively)
  • passes --no-frozen-lockfile only for pnpm, nothing extra otherwise

When pnpm is detected nothing runs — early return, zero change in behavior.
Non-monorepo templates are also unaffected (conversion is gated on
pnpm-workspace.yaml existing).

All existing shadcn tests pass with zero changes needed to any other test
file (60/60 files, 1197/1197 tests). Updated scaffold.test.ts to cover
the new per-PM install arg behavior. Also tested end-to-end locally with
bun, pnpm, and npm monorepo init.

All monorepo templates hardcoded `packageManager: "pnpm"` which
meant running `bunx --bun shadcn@latest init --monorepo` would
still shell out to `pnpm install`, triggering Corepack and crashing
under Bun because `process.mainModule` is readonly there.

This removes the hardcoded pnpm override from every monorepo template
config so `getPackageManager()` can actually detect what the user is
running. The scaffold step now adapts the cloned template on the fly:

- strips the `packageManager` field from package.json (avoids Corepack)
- converts pnpm-workspace.yaml to a `"workspaces"` array in package.json
- removes pnpm-lock.yaml
- rewrites `workspace:*` refs to `"*"` when the detected PM is npm
  (npm doesn't support the workspace: protocol)
- picks the right install flags per PM (`--no-frozen-lockfile` for pnpm,
  nothing extra for bun/npm/yarn)

pnpm behavior is completely unchanged — `adaptWorkspaceConfig` early-
returns when the detected PM is pnpm.
@vercel
Copy link
Copy Markdown
Contributor

vercel bot commented Mar 11, 2026

@devinscodebase is attempting to deploy a commit to the shadcn-pro Team on Vercel.

A member of the Team first needs to authorize it.

@shadcn
Copy link
Copy Markdown
Collaborator

shadcn commented Mar 11, 2026

I'll take a look. Thank you.

@shadcn shadcn self-assigned this Mar 11, 2026
@shadcn shadcn added the area: roadmap This looks great. We'll add it to the roadmap, review and merge. label Mar 11, 2026
@vercel
Copy link
Copy Markdown
Contributor

vercel bot commented Mar 11, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
ui Ignored Ignored Preview Mar 11, 2026 2:02pm

Request Review

@devinscodebase
Copy link
Copy Markdown
Contributor Author

I'll take a look. Thank you.

Great - let me know if you need anything :)

@shadcn shadcn merged commit abf1555 into shadcn-ui:main Mar 13, 2026
5 of 7 checks passed
@devinscodebase devinscodebase deleted the fix/monorepo-package-manager-detection branch March 13, 2026 07:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: roadmap This looks great. We'll add it to the roadmap, review and merge.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug]: Error initializing Next.js monorepo with Bun: workspace dependencies not found

2 participants