ui icon indicating copy to clipboard operation
ui copied to clipboard

Uncaught Error: Cannot find module

Open blackrose77 opened this issue 2 years ago • 2 comments

Hi, I have been looking for an answer but I could not find one that worked. I have a reactJs and I need to make shadcn work with It. I have been following tutorials to try to install It. I am using this command line: npx shadcn-ui@latest init with this Capture d’écran 2023-10-30 à 15 16 29

and here is my tsconfig : Capture d’écran 2023-10-30 à 15 17 30

The installation worked then I use this command to try to install a component : npx shadcn-ui@latest add button

My component appears in the component/ui folder. My typescript does not trigger any error but when I start the server, and try to use my component, in this case a simple button, I got : Capture d’écran 2023-10-30 à 15 21 17

I also tried using path like "../../components/ui/button" but It does not work as well. I am lost right now and need help please

blackrose77 avatar Oct 30 '23 14:10 blackrose77

I have a theory about where your issue is. To confirm it, I'd like to ask you for the path to the 'components' folder?

My theory is as follows:

When you install shadcn-ui, it usually creates a 'components' folder. Currently, you are trying to access the module as '@/components/ui/button'. Since you have:

"paths": {
  "@/*": ["./*"]
},

It takes the '@' from the root of the project, which means you are trying to access the module at 'root/components/ui/button'. I have a theory that your 'components' folder is not in the project's root. Can you check this?

For example, in my projects, I have the 'components' folder inside 'src', so I have configured the paths like this:

"paths": {
  "@/*": ["./src/*"]
},
```"

damiansire avatar Nov 02 '23 08:11 damiansire

Hi Damiansire, my components folder was in the project root and I try to use relative path but It was still not working, but you gave me the idea to try to do the exact same thing but this time I used the src folder and with a relative path only It is working. I don't know why It does not make any sense for me.

blackrose77 avatar Nov 02 '23 12:11 blackrose77

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.

shadcn avatar Feb 13 '24 23:02 shadcn