ui: Cannot find module '../../@/components/ui/button' and Cannot find module '@/lib/utils' or its corresponding type declarations.
So i just started ts + vite + tailwind. tried installing shadcn and the button component to test it out, but it gave this error message. tried looking for the same issue here but didnt find any solution. i have run npx shadcn-ui init and it still didnt work, i dont use react server component.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 35
I solved this problem by adding
baseUrl,pathsconfig totsconfig.app.json.Like below:
I encountered the same issue, my mistake was in pasting
"baseUrl": ".", "paths": { "@/*": ["./src/*"] }outside the compilerOptions, please do checkThis works for me. Thank you 👍
@vim-diesel also update your
components.jsonwith:My mistake was configuring ts config file after
npx shadcn-ui@latest initI resolved by again going through the setup, and this time I setup ts config file first
"compilerOptions": { "baseUrl": ".", "paths": { "@/*": [ "./src/*" ] }, }Then ran
npx shadcn-ui@latest initIncase if it helps someone
@shadcn My
tsconfig.jsonlooks like this:In fact, the alias “works”: I don’t get any direct typescript error (the import of the
cnfunction is accepted by typescript with the alias just above). The error occurs only during the compilation.@StreetDevs I think that you have the same folder structure as mine:
Solved the problem by changing the following line in the
button.tsxfile:by:
It looks like the
@alias doesn’t work (I don’t know why though…)Reference: https://stackoverflow.com/a/75121301/8345133 In the
tsconfig.app.jsonfile, add"extends": "./tsconfig.json"as shown below:This worked for me.
I solved this problem by just moving the downloaded components into a ui folder in my src/components/ui and also the lib/utils. i think i messed up when I first init the library.
fiz seguindo o codigo do colega, mas como podem ver na iamgem abaixo ele continua sendo criado o @na raiz
I have the same issue but i tried all the above but is still does not work
You can try this
npx shadcn-ui@latest initThanks, this worked for me 😃
It’s finally working for me!
When using shadcn/ui, you might encounter import issues due to path aliasing configuration.
For example if you have this kind of structure
Project Structure
Required Configuration
You need to configure both
vite.config.tsandtsconfig.json:This will allow imports like:
Key Points
Make sure paths match exactly in both files You could have to restart TS Server after config changes
How to Restart TypeScript Server
Using Command Palette
Cmd/Ctrl + Shift + PYou are GodSend.
Thanks @yeongbin-jo, I was editing all tsconfig files except tsconfig.app.json, I don’t understand why we have a lot of tsconfig files but anyway you saved my day
@stephanebruckert sorry I deleted my comment. I messed up putting the compiler options in before initializing. I deleted the project and tried again and seems to be working okay now.
works, however the shadcn cli moves it to
/(above src) by default, which causes this issue:@shadcn do you recommend to put @ into
srcby default (React app here btw), if so should the cli take care of it?