ui icon indicating copy to clipboard operation
ui copied to clipboard

[bug]: Cannot initialize components.json using `npx shadcn@latest init` after manual installation of shadcn (for my React app)

Open pr2tik1 opened this issue 1 year ago • 12 comments

Describe the bug

I cannot intialize the component.json by following manual installation followed by npx shadcn@latest init.

Affected component/components

components.json

How to reproduce

  1. Install shadcn from - https://ui.shadcn.com/docs/installation/manual
  2. Setup components.json - https://ui.shadcn.com/docs/components-json

Codesandbox/StackBlitz link

No response

Logs

npx shadcn@latest init
⠙
✔ Preflight checks.
✖ Verifying framework.

We could not detect a supported framework at /my-app/frontend.
Visit https://ui.shadcn.com/docs/installation/manual to manually configure your project.
Once configured, you can use the cli to add components.

System Info

GitHub Workspaces

Before submitting

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

pr2tik1 avatar Sep 06 '24 06:09 pr2tik1

The documentation mentions: Note: ... only required if you're using the CLI ... In the actual code:

  if (!projectInfo || projectInfo?.framework.name === "manual") {
    errors[ERRORS.UNSUPPORTED_FRAMEWORK] = true
    frameworkSpinner?.fail()
    logger.break()

You don't need “components.json” because you're using the “manual” method, not the “cli” method

joseph0926 avatar Sep 06 '24 09:09 joseph0926

I'm not sure if you're referring to the "manual installation" process, which might be getting confused with adding configurations using components.json or the CLI for component additions "manually".

However, as mentioned here, downgrading did help resolve my issue.

pr2tik1 avatar Sep 06 '24 09:09 pr2tik1

Didn't you do a “Manual Installation” via “https://ui.shadcn.com/docs/installation/manual”?

“shadcn” says that there was a major ‘cli’ update on 2024.08 ”https://ui.shadcn.com/docs/changelog” And it added the code I mentioned in my comment above, among other files that were not present in the 0.8.0 version.

  if (!projectInfo || projectInfo?.framework.name === "manual") {
    errors[ERRORS.UNSUPPORTED_FRAMEWORK] = true
    frameworkSpinner?.fail()
    logger.break()

https://github.com/shadcn-ui/ui/blob/078dfe66072c4ca780bbc99d4ad4b13b1f44fe7e/packages/shadcn/src/preflights/preflight-init.ts#L54


I don't know if this is a bug or intentional on the team's part, but in the latest version, npx shadcn@latest init is blocked if you proceed to “Manual Installation”.

What do you think about this?

joseph0926 avatar Sep 06 '24 09:09 joseph0926

https://github.com/shadcn-ui/ui/discussions/4685#discussioncomment-10523330

pr2tik1 avatar Sep 06 '24 09:09 pr2tik1

#4685 (comment)

The reason that author(fivestones) got that error is because he didn't have a next.config file This is not a newer version error;;

Check the link code below “https://github.com/shadcn-ui/ui/blob/078dfe66072c4ca780bbc99d4ad4b13b1f44fe7e/packages/shadcn/src/utils/get-project-info.ts#L71C1-L77C4”

joseph0926 avatar Sep 06 '24 09:09 joseph0926

Thanks @joseph0926, this is helpful!

I agree, especially if it's intentionally excluded for React-based setups (which I achieved "manually" 😅), or if it's expected to detect React via @vitejs/plugin-react (for which we see here).

I'm not entirely sure about this, but I appreciate it—your explanation makes the reason clear. Thanks again !

pr2tik1 avatar Sep 06 '24 14:09 pr2tik1

I agree, especially if it's intentionally excluded for React-based setups (which I achieved "manually" 😅), or if it's expected to detect React via @vitejs/plugin-react (for which we see here).

I'm not entirely sure about this, but I appreciate it—your explanation makes the reason clear. Thanks again !

Glad it helped a little bit : )

joseph0926 avatar Sep 06 '24 22:09 joseph0926

I am not using vite, instead Bun.build directly; downgrade is the only option?

7flash avatar Oct 09 '24 07:10 7flash

Also met the same issue using webpack. Could webpack become a supported framework? Actually, it is acceptable to use mannualy installation method for init shadcn-ui. Is there any plan to use cli to add components at least?

zachary-wang12 avatar Oct 13 '24 12:10 zachary-wang12

I dont get it too. So this is the output right?

We could not detect a supported framework at /Users/ml/development/projects/chrome/reachpanda-extension.
Visit https://ui.shadcn.com/docs/installation/manual to manually configure your project.
Once configured, you can use the cli to add components.

I thought this means i need to do the manual installation as mentioned in the docs and "once its configured, one can use the cli to add components", But i cant use the CLI to add components even after doing the manual installation.

I am using wxt for chrome extension development and behind the scenes it uses pretty standard react/vite setup. And i ve seen a wxt project using npx with shadcn to add components, so it cant be that it checks for a nextjs config. There must be something else the CLI looks out for which i am missing.

Update: ok i figured it out. Its a bit misleading. Looks like you need to manually create the components.json file and the related folders/files which are part of the json file. After that i was able to use the CLI to add single shadcn components.

logemann avatar Oct 17 '24 06:10 logemann

I dont get it too. So this is the output right?

We could not detect a supported framework at /Users/ml/development/projects/chrome/reachpanda-extension.
Visit https://ui.shadcn.com/docs/installation/manual to manually configure your project.
Once configured, you can use the cli to add components.

I thought this means i need to do the manual installation as mentioned in the docs and "once its configured, one can use the cli to add components", But i cant use the CLI to add components even after doing the manual installation.

I am using wxt for chrome extension development and behind the scenes it uses pretty standard react/vite setup. And i ve seen a wxt project using npx with shadcn to add components, so it cant be that it checks for a nextjs config. There must be something else the CLI looks out for which i am missing.

Update: ok i figured it out. Its a bit misleading. Looks like you need to manually create the components.json file and the related folders/files which are part of the json file. After that i was able to use the CLI to add single shadcn components.

This worked for me with one addition - I realized I was missing a jsconfig.json file in my root directory that allow the @/ import aliases to work properly. Adding that file made the CLI work: { "compilerOptions": { "baseUrl": ".", "paths": { "@/*": ["./src/*"] } } }

kejiat avatar Nov 12 '24 03:11 kejiat

This issue has been automatically marked as stale due to one year of inactivity. It will be closed in 7 days unless there’s further input. If you believe this issue is still relevant, please leave a comment or provide updated details. Thank you. (This is an automated message)

shadcn avatar Nov 12 '25 23:11 shadcn

This issue has been automatically closed due to one year of inactivity. If you’re still experiencing a similar problem or have additional details to share, please open a new issue following our current issue template. Your updated report helps us investigate and address concerns more efficiently. Thank you for your understanding! (This is an automated message)

shadcn avatar Nov 20 '25 23:11 shadcn