ui icon indicating copy to clipboard operation
ui copied to clipboard

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

Open ronijaat opened this issue 1 year ago • 5 comments

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

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

ronijaat avatar Sep 13 '24 05:09 ronijaat

Same problem on mac

jmfp avatar Sep 13 '24 08:09 jmfp

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

mellolauro avatar Sep 13 '24 14:09 mellolauro

I have the same problem.

bretzke avatar Sep 14 '24 01:09 bretzke

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.

ericjy avatar Sep 18 '24 23:09 ericjy

THE PROBLEM IS SOLVED!!!

I have exactly the same problem. image

Replace the current line:

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

On this line:

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

image

suprunchuk avatar Sep 27 '24 08:09 suprunchuk

The issue is not fixed, but can be handled manually quickly.

mschilde avatar Oct 13 '24 21:10 mschilde

"Replace the line import { toast } from "@/components/hooks/use-toast" Uploading Screenshot from 2024-11-09 08-40-45.png… with import { toast } from "@/components/hooks/use-toast". Screenshot from 2024-11-09 08-40-42

malo-dev avatar Nov 09 '24 06:11 malo-dev

The problem is still not resolved by default.

nikrishttam avatar Jan 02 '25 11:01 nikrishttam

still not fixed

wpenistone avatar Oct 20 '25 12:10 wpenistone