Uncaught Error: Cannot find module
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
and here is my tsconfig :
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 :
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
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/*"]
},
```"
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.
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.