Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug]: npx shadcn@latest add toast creating hooks folder outside components #4828

Open
2 tasks done
ronijaat opened this issue Sep 13, 2024 · 4 comments
Open
2 tasks done
Labels
bug Something isn't working

Comments

@ronijaat
Copy link

Describe the bug

PS C:\Users\HP\Desktop\office\package-maker> npx shadcn@latest add toast
Need to install the following packages:
[email protected]
Ok to proceed? (y) y

✔ Checking registry.
✔ Installing dependencies.
✔ Created 3 files:

  • components\ui\toast.tsx
  • hooks\use-toast.ts
  • components\ui\toaster.tsx

Failed to compile

Next.js (14.2.5) out of date (learn more)
./components/ui/toaster.tsx:3:1
Module not found: Can't resolve '@/components/hooks/use-toast'
1 | "use client"
2 |

3 | import { useToast } from "@/components/hooks/use-toast"
| ^
4 | import {
5 | Toast,
6 | ToastClose,

https://nextjs.org/docs/messages/module-not-found

Affected component/components

Toast

How to reproduce

  1. npx shadcn@latest add toast

Codesandbox/StackBlitz link

yes

Logs

no

System Info

windows 11

Before submitting

  • I've made research efforts and searched the documentation
  • I've searched for existing issues
@ronijaat ronijaat added the bug Something isn't working label Sep 13, 2024
@jmfp
Copy link

jmfp commented Sep 13, 2024

Same problem on mac

@mellolauro
Copy link

Problem win 11 . node -v -- > v20.17.0
npm -v --> 10.8.2

npx shadcn@latest init
✔ Preflight checks.
✔ Verifying framework. Found Next.js.
✔ Validating Tailwind CSS.
✔ Validating import alias.

Something went wrong. Please check the error below for more details.
If the problem persists, please open an issue on GitHub.

request to https://ui.shadcn.com/r/styles/index.json failed, reason: self-signed certificate in certificate chain

@bretzke
Copy link

bretzke commented Sep 14, 2024

I have the same problem.

@ericjy
Copy link

ericjy commented Sep 18, 2024

Solution

This solution works for me. Modify the newly added components/ui/toaster.tsx file:

Change

import { useToast } from "@/components/hooks/use-toast";

to

import { useToast } from "@/hooks/use-toast";

This is because the use-toast.tsx is added to the hooks dir, not components/hooks dir.

Or you can move the use-toast.tsx to components/hooks dir, which might be a better organization depending on your project setup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants