[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
- make empty project
- execute
npx shadcn@canary init - 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
me too, windows 11
me too, window 11
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
also happens with
npx shadcn@latest init
only fix is to go in my-app and then run pnpm install.
SOLVED WIN 11: For me was running the terminal as administrator (used cmd)
SOLVED WIN 11: For me was running the terminal as administrator (used cmd)
That's because you are using pnpm. pnpm works the problem is with using npm
SOLVED WIN 11: For me was running the terminal as administrator (used cmd)
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.
mac, npm. failing as above when choosing monorepo during init
same issue for me. like @qoalu . can someone help?
same issue but with pnpm!!
same issue here
windows 11
tried with powershell as admin permissions and still failing
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:
- change
dependenciesanddevDependenciesvalues in package.json files from"workspace:*"and"workspace:^"to"*" - go to root package.json file and remove pnpm as your package manager while adding
apps/*andpackages/*as workspaces. - 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:
[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:*
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.
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
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.
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