ui: [bug]: npm error Unsupported URL Type "workspace:": workspace:* using npx shadcn@canary init

Describe the bug

When creating a new project and running npx shadcn@canary init, selecting the next.js(monorepo) version results in an EUNSUPPORTEDPROTOCOL error.

In my opinion, The reason for this is likely that Shadcn defaults to npm when it cannot detect a package manager, then attempts to run the npm install command. However, the monorepo template files are based on pnpm, which causes compatibility issues and results in the error

Affected component/components

CLI init(monorepo)

How to reproduce

  1. make empty project
  2. execute npx shadcn@canary init
  3. Would you like to start a new project? › Next.js (Monorepo)

Codesandbox/StackBlitz link

No response

Logs

shadcn-mono-test git:(main) npx shadcn@canary init                            

✔ The path /Users/jh/shadcn-mono-test does not contain a package.json file.
  Would you like to start a new project? › Next.js (Monorepo)
✔ What is your project named? … my-app
✖ Something went wrong creating a new Next.js monorepo.
Something went wrong. Please check the error below for more details.
If the problem persists, please open an issue on GitHub.

Command failed with exit code 1: npm install
npm error code EUNSUPPORTEDPROTOCOL
npm error Unsupported URL Type "workspace:": workspace:*
npm error A complete log of this run can be found in: /Users/jh/.npm/_logs/2025-01-22T06_59_21_296Z-debug-0.log

System Info

mac

Before submitting

  • I’ve made research efforts and searched the documentation
  • I’ve searched for existing issues

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 3
  • Comments: 16

Most upvoted comments

mac, npm. failing as above when choosing monorepo during init

This is an issue with the package manager in your monorepo. The shadcn init script is returning a pnpm repository, not npm. To turn the pnpm repository into a npm repository:

  1. change dependencies and devDependencies values in package.json files from"workspace:*" and "workspace:^" to "*"
  2. go to root package.json file and remove pnpm as your package manager while adding apps/* and packages/* as workspaces.
  3. remove any additonal pnpm config files in your project.

See here: https://turbo.build/repo/docs/crafting-your-repository/managing-dependencies

Why was this issue closed? As of 2.5.0, shadcn init still doesn’t support package managers other than pnpm when using the monorepo template. I had to spend an hour debugging this today.

$ npx shadcn init

Need to install the following packages:
shadcn@2.5.0
Ok to proceed? (y) y

npm warn deprecated node-domexception@1.0.0: Use your platform's native DOMException instead
√ The path F:\repos does not contain a package.json file.
  Would you like to start a new project? » Next.js
√ What is your project named? ... shadcn-test-one
✔ Creating a new Next.js project.
√ Which color would you like to use as the base color? » Neutral
✔ Writing components.json.
✔ Checking registry.
✔ Updating CSS variables in app\globals.css
$ npx shadcn init

Need to install the following packages:
shadcn@2.5.0
Ok to proceed? (y) y

npm warn deprecated node-domexception@1.0.0: Use your platform's native DOMException instead
√ The path F:\repos does not contain a package.json file.
  Would you like to start a new project? » Next.js (Monorepo)
√ What is your project named? ... shadcn-test-two
✖ Something went wrong creating a new Next.js monorepo.
Something went wrong. Please check the error below for more details.
If the problem persists, please open an issue on GitHub.

Command failed with exit code 1: npm install
npm error code EUNSUPPORTEDPROTOCOL
npm error Unsupported URL Type "workspace:": workspace:*

The only way i got this to work is to install shadcn after installing next with “npx create-next-app”. Essentially you need an existing nextjs project to install it in through npm.

Image