ui icon indicating copy to clipboard operation
ui copied to clipboard

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

Open whdgur5717 opened this issue 1 year ago • 12 comments

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

  • [x] I've made research efforts and searched the documentation
  • [x] I've searched for existing issues

whdgur5717 avatar Jan 22 '25 07:01 whdgur5717

me too, windows 11

xidoke avatar Jan 24 '25 15:01 xidoke

me too, window 11

babually avatar Jan 27 '25 11:01 babually

npx shadcn@canary init
✔ The path /home/user/code does not contain a package.json file.
  Would you like to start a new project? › Next.js (Monorepo)
✔ What is your project named? … baseline
✖ 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: /home/user/.npm/_logs/2025-01-29T01_31_39_194Z-debug-0.log

Me too, Ubuntu 22.04

nooikko avatar Jan 29 '25 01:01 nooikko

also happens with npx shadcn@latest init only fix is to go in my-app and then run pnpm install.

heymaaz avatar Jan 29 '25 22:01 heymaaz

SOLVED WIN 11: For me was running the terminal as administrator (used cmd)

Image

brasillero avatar Feb 05 '25 12:02 brasillero

SOLVED WIN 11: For me was running the terminal as administrator (used cmd)

Image

That's because you are using pnpm. pnpm works the problem is with using npm

heymaaz avatar Feb 05 '25 13:02 heymaaz

SOLVED WIN 11: For me was running the terminal as administrator (used cmd) Image

That's because you are using pnpm. pnpm works the problem is with using npm

My bad, for me, even pnpm wasn't working. This soved my issue.

brasillero avatar Feb 05 '25 18:02 brasillero

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

qoalu avatar Feb 08 '25 11:02 qoalu

same issue for me. like @qoalu . can someone help?

riteshganatra avatar Feb 12 '25 03:02 riteshganatra

same issue but with pnpm!!

Image

Nothehi avatar Mar 10 '25 06:03 Nothehi

same issue here

Image

windows 11

tried with powershell as admin permissions and still failing

sebasbeleno avatar Mar 12 '25 20:03 sebasbeleno

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

TheWuster935 avatar Mar 15 '25 19:03 TheWuster935

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:
[email protected]
Ok to proceed? (y) y

npm warn deprecated [email protected]: 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:
[email protected]
Ok to proceed? (y) y

npm warn deprecated [email protected]: 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:*

Limezero avatar Apr 25 '25 16:04 Limezero

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

Chukwudi-O avatar May 25 '25 18:05 Chukwudi-O

This is still an issue I had to delete these lines from my root package.json in my monorepo

	"packageManager": "[email protected]",
	"workspaces": [
		"apps/*",
		"packages/*"
	],

Then rerun the command

bunx --bun shadcn@latest init

ColinCee avatar Jun 25 '25 17:06 ColinCee

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

In case there is another brilliant mind like me... this means: run npx shadcn init after a successfully running npx create-next-app@latest. Finally start the app with npm run dev

nagarciah avatar Jun 27 '25 17:06 nagarciah