ui icon indicating copy to clipboard operation
ui copied to clipboard

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

Open joeylin opened this issue 2 years ago • 18 comments

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

joeylin avatar Jun 28 '23 05:06 joeylin

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

EugenePeter avatar Jun 28 '23 06:06 EugenePeter

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

plbstl avatar Jun 28 '23 06:06 plbstl

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

EugenePeter avatar Jun 28 '23 07:06 EugenePeter

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

plbstl avatar Jun 28 '23 07:06 plbstl

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 avatar Jun 28 '23 07:06 EugenePeter

Screenshot 2023-06-28 163827

EugenePeter avatar Jun 28 '23 07:06 EugenePeter

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

plbstl avatar Jun 28 '23 07:06 plbstl

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

plbstl avatar Jun 28 '23 07:06 plbstl

@joeylin @EugenePeter Duplicate of #746

dan5py avatar Jun 28 '23 07:06 dan5py

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

Sukrittt avatar Jun 28 '23 12:06 Sukrittt

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.

shuvro111 avatar Jun 28 '23 17:06 shuvro111

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 avatar Jun 29 '23 02:06 joeylin

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

joeylin avatar Jun 29 '23 02:06 joeylin

@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",

dan5py avatar Jun 29 '23 08:06 dan5py

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

AlissonSteffens avatar Jun 30 '23 00:06 AlissonSteffens

In my case,

  • "css": "app/globals.css",
  • "css": "src/app/globals.css", This method was not helpful. I restarted the project without using the src directory. now done

BGM-109 avatar Jun 30 '23 05:06 BGM-109

ok, i fixed it using below config:

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

and delete /app/* folder thanks everyone.

joeylin avatar Jun 30 '23 07:06 joeylin

@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

fazlay avatar Jul 01 '23 14:07 fazlay

+1 this solves the issue

laxmariappan avatar Jul 04 '23 23:07 laxmariappan

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

AbdullahMufti avatar Jul 13 '23 07:07 AbdullahMufti

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

image

ealipio avatar Jul 14 '23 21:07 ealipio

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

AbdullahMufti avatar Jul 15 '23 06:07 AbdullahMufti

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.

get6 avatar Jul 16 '23 14:07 get6

When you run npx shadcn-ui@latest init

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

src/app/globals.css

✌️

hadnazzar avatar Jul 19 '23 17:07 hadnazzar

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

AbdullahMufti avatar Jul 19 '23 18:07 AbdullahMufti

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

vdespa avatar Jul 21 '23 21:07 vdespa

+1 solved

git-peto avatar Jul 31 '23 15:07 git-peto

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?

harrygreen avatar Aug 06 '23 19:08 harrygreen

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,

  • updated the globals.css location with src/ inside the components.json
  • so it will be like this -> "css": "src/app/globals.css",
  • deleted the app folder outside the src folder
  • deleted the current .next folder and re run the server and it worked for me

ateebasif avatar Aug 20 '23 14:08 ateebasif

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

Pranomvignesh avatar Aug 24 '23 07:08 Pranomvignesh