shadcn-ui / ui

Beautifully designed components that you can copy and paste into your apps. Accessible. Customizable. Open Source.
https://ui.shadcn.com
MIT License
62.84k stars 3.53k forks source link

404 error when run "npx shadcn-ui@latest init" #755

Closed joeylin closed 1 week ago

joeylin commented 1 year ago

I create new application with next.js and shadcn, when I installed next.js, the server worked, and I can see the page in the browser. but, after I run "npx shadcn-ui@latest init", the page always redirects to error page. image

EugenePeter commented 1 year ago

I am having the same issues, installed shadcn just now.

plbstl commented 1 year ago

I cannot reproduce this. Can you output the list of files here? Try tree --gitignore

EugenePeter commented 1 year ago

Try creating a next js app, observe that pages are accessible, then run npx shadcn-ui@latest init, after setting up all pages redirect to 404

plbstl commented 1 year ago

Okay. What is the command you used to create the Next.js project? And use the default options?

EugenePeter commented 1 year ago

The command I ran is npx create-next-app@latest when I created the next app. Then npm run dev to run the app. I have been developing a next js 13.4 app for the past few weeks. I haven't committed my changes for today, installed shadcn then all pages suddenly redirect to 404 page.

EugenePeter commented 1 year ago

Screenshot 2023-06-28 163827

plbstl commented 1 year ago

Can you check the import alias in tsconfig and components.json if they match?

plbstl commented 1 year ago

The CLI init isn't supposed to alter your code in the /app directory, except when creating global css

dan5py commented 1 year ago

@joeylin @EugenePeter Duplicate of #746

Sukrittt commented 1 year ago

It happened for me because it created a new app folder with globals.css. However my app folder was inside the src folder.

shuvro111 commented 1 year ago

It happened for me because it created a new app folder with globals.css. However my app folder was inside the src folder.

Thanks man! It was such a silly mistake that I didn't find it. Thanks for the help.

joeylin commented 1 year ago

It happened for me because it created a new app folder with globals.css. However my app folder was inside the src folder.

Thanks man! It was such a silly mistake that I didn't find it. Thanks for the help.

then how to fix it ? move the app folder to project folder ?

joeylin commented 1 year ago

I don't know why, I just follow the tips step by step, but it seems the default action does not work.

dan5py commented 1 year ago

@joeylin If you are using the src folder you need to delete the app folder (move the globals.css file to the real app folder before deleting) that has been created when running the shadcn-ui init command.

Then you need to update the components.json file by changing this line:

- "css": "app/globals.css",
+ "css": "src/app/globals.css",
AlissonSteffens commented 1 year ago

It happened for me because it created a new app folder with globals.css. However my app folder was inside the src folder.

thats it, thanks

BGM-109 commented 1 year ago

In my case,

joeylin commented 1 year ago

ok, i fixed it using below config:

"css": "src/app/globals.css"

and delete /app/* folder thanks everyone.

fazlay commented 1 year ago

@joeylin If you are using the src folder you need to delete the app folder (move the globals.css file to the real app folder before deleting) that has been created when running the shadcn-ui init command.

Then you need to update the components.json file by changing this line:

- "css": "app/globals.css",
+ "css": "src/app/globals.css",

this solved my issue

laxmariappan commented 12 months ago

+1 this solves the issue

AbdullahMufti commented 11 months ago

image 404 Error After Installing Shadcn ui

  1. It occurs when we use src folder for next app creation.
  2. It occurs when correct path to global.css is not mentioned during init shadcn process
  3. Correct path is /src/app/global.css but
  4. Default path is app/global.css it creates another app directory in root folder, while we are using app directory is src folder, and then 404 error occurs What you need to do is i) copy content from /app/global.css to /src/app/global.css ii) delete app directory in root folder
ealipio commented 11 months ago

you can avoid this issue just setting the proper path of your global.css when you start using shadcn:

image

AbdullahMufti commented 11 months ago

exactly.. it is not a bug.... it is a mistake at user(developer)'s end. Team behind shadcn can takecare of it, by searching path to global.css and not asking the user

get6 commented 11 months ago

Wow 🚀 I love you of all! You saved me 👍 I had followed this instruction. But I think it would be better if there was an explanation to make sure the app folder exists in the src folder.

hadnazzar commented 11 months ago

When you run npx shadcn-ui@latest init

Where is your global CSS file? Please answer as below.

src/app/globals.css

✌️

AbdullahMufti commented 11 months ago

default path is src/app/globals.css if we select yes for following Would you like to use src/ directory with this project? › No / Yes while creating next application

vdespa commented 11 months ago

shadcn should use the defaults that Next.js uses, with the src folder. Otherwise debugging what happens is a waste of time.

git-peto commented 11 months ago

+1 solved

harrygreen commented 11 months ago

I'm getting the same/similar issue, but I'm using /pages, not /app. My components.json file points to src/styles/global.css, which is correct. It's all fine locally until I deploy to a live URL (via Amplify, which isn't my choice). Has anyone experienced this?

ateebasif commented 10 months ago

image 404 Error After Installing Shadcn ui

  1. It occurs when we use src folder for next app creation.
  2. It occurs when correct path to global.css is not mentioned during init shadcn process
  3. Correct path is /src/app/global.css but
  4. Default path is app/global.css it creates another app directory in root folder, while we are using app directory is src folder, and then 404 error occurs What you need to do is i) copy content from /app/global.css to /src/app/global.css ii) delete app directory in root folder

thanks man this, worked like a charm form me. As i was using src folder with nextjs so when i installed shadcn it created another app folder for me and it had only globals.css files. so what i did was,

Pranomvignesh commented 10 months ago

@ateebasif Thanks for this solution. This one worked for me

atlas700 commented 9 months ago

i create next js 13 app with pnpm pnpm create next-app@latest

and still got the same error after init shadcnUI

atisamakhtar commented 9 months ago

image 404 Error After Installing Shadcn ui

  1. It occurs when we use src folder for next app creation.
  2. It occurs when correct path to global.css is not mentioned during init shadcn process
  3. Correct path is /src/app/global.css but
  4. Default path is app/global.css it creates another app directory in root folder, while we are using app directory is src folder, and then 404 error occurs What you need to do is i) copy content from /app/global.css to /src/app/global.css ii) delete app directory in root folder

Yes it worked amazing.

otmaneomry commented 9 months ago

@joeylin If you are using the src folder you need to delete the app folder (move the globals.css file to the real app folder before deleting) that has been created when running the shadcn-ui init command.

Then you need to update the components.json file by changing this line:

- "css": "app/globals.css",
+ "css": "src/app/globals.css",

thanks it's worked for me

halimkun commented 7 months ago

+1 solved. @ateebasif Thanks for https://github.com/shadcn-ui/ui/issues/755#issuecomment-1685303139 solution. This one worked for me

Mr-Babarkhan commented 7 months ago

@joeylin If you are using the src folder you need to delete the app folder (move the globals.css file to the real app folder before deleting) that has been created when running the shadcn-ui init command. Then you need to update the components.json file by changing this line:

- "css": "app/globals.css",
+ "css": "src/app/globals.css",

this solved my issue

Thanks man

abdurrehmaan commented 7 months ago

I found video demostration of this issue on youtube and worked for me (y) here is the link https://youtu.be/o_D-tdcpyzQ?si=upN60yRpAeMeaIiT

Note: video is in different language (not English)

pratik2e commented 7 months ago
"src/app/globals.css",

ah looking for this thanks man.

ThanHtikeZawGithub commented 7 months ago

Thank u! I have solved my issue

JohnGemstone commented 6 months ago

wouldn't it be better to auto detect whether the repo uses a src folder or not? what scenario is there for having the next app folder in the root directory as well as a src folder?

shadcn commented 1 week ago

This issue has been automatically closed because it received no activity for a while. If you think it was closed by accident, please leave a comment. Thank you.