ui: [bug]: Module not found: Error: Can't resolve '@/components/ui .......
Describe the bug
When using create react app and compiling / starting the react-scripts start command, you get Module not found: Error: Can’t resolve '@/components/ui … Also found here: https://github.com/shadcn-ui/ui/issues/1101#issuecomment-1998726992
Affected component/components
all
How to reproduce
create a react app by create react app (i added typescript) add shadcn create a component run start script
Codesandbox/StackBlitz link
No response
Logs
No response
System Info
(MacOS)(Chromium browser) Create React App
Before submitting
- I’ve made research efforts and searched the documentation
- I’ve searched for existing issues
About this issue
- Original URL
- State: open
- Created 3 years ago
- Reactions: 6
- Comments: 53
Okay, thank you @vasvalstan for providing all the screenshots and I have seen them, change it to something like this.
Simply set the paths or aliases in this file.
tsconfig.json
Then extends in tsconfig.app.json
Restore the content of the tsconfig.node.json file to the original. For the vite.config.ts and components.json file, there is no problem.
Delete the @ folder and then run
npx shadcn-ui@latest initagain.I had the same problem, and I spent the whole night messing around with it.
I finally found the solution.
Reference : https://stackoverflow.com/questions/50679031/why-are-these-tsconfig-paths-not-working
Just add one line of code in tsconfig.app.json as follows:
So the whole code looks like this:
Hope this helps those of you who have the same problem.
You can import like this ==> import Image from “next/image”; see this image

My image folder is not in my src folder; instead, it’s located in the public folder, import Image from “next/image”;
try this ==> @/app/components/ui/button
so push them in app this is not good way, like this
Oh, brother, you don’t understand my point. You’re right, his [program] cannot give you a red line, but your error is here.not giving the correct file path. Just try this ==> @/app/components/ui/button
While I appreciate your enthusiasm, your replies are so wrong it makes my head hurt.
It does not matter (at least it should not) what the file structure is, when my imports are correct.
As I stated earlier, it seems to be a problem with react-scripts!
This topic needs some experts in that direction.
I’ve been using
create-react-appand ran into the same issue.create-react-appdoesn’t allow path aliases to be overwritten to “@” out of the box.I’ve fixed the “
Module not found”-Error by adding craco to my project. Craco allows you to override the CRA configurations.Here’s how:
Add craco to your project: run
npm install @craco/cracoCreate a
craco.config.js-File in the root of your project and add the following to it:If you’re using React TypeScript, make sure the ‘@’-alias is also present in your
tsconfig.json:Note: Inside
tsconfig.json, the paths need to be specified with/*to explicitly add all subelements.cracoby replacing thereact-scriptcalls withcracoin yourpackage.jsonsuch as:is it fixed for create-react-app yet?
I encountered similar issue. I set up a React project with TypeScript using
create-react-appand integrated Tailwind CSS. Initially, I set up paths intsconfig.jsonas follows:and defined aliases in
component.jsonlike this:this placed shadcn components at the
rootlevel , don’t know what causing issue but I encountered a module error.To resolve this, I modified
tsconfig.json:and adjusted
component.json:this placed shadcn components inside
srcdirectory. Although ‘@’ alias import doesn’t work in this case, I can only be able to import using relative paths, likeimport Button from './components/ui/button', with@alias import The TypeScript language server functions correctly, but upon compilation, it throws a module error.not working
working

Hi If you are using ‘use client’ at top in any file then remove it
Thanks @alfinauzikri it actually worked!!!
Set the aliases in components.json as follows:
Delete the @ folder and then run
npx shadcn-ui@latest initagain. Make sure the tsconfig.json file is set up properly.That’s right, my project bootstrapped with Vite. @SureshPradhana
It’s unfortunate that create-react-app has problems handling aliases.
I tried it earlier and ended up the same as @Quietscher
I saw that someone can make shadcn/ui work well with create-react-app and he has also provided a starter template: https://github.com/ahmad1702/shadcn-ui-cra
Thats the point. I just want the create-react-app. No Vite or Next.js.
Ohh thank you @alfinauzikri 👏
I am using next js v15.1.3 and react 19.0 , encountered same issue while deploying to vercel, but same works fine in my system. Error encountered in vercel while running num run build Error Sample:
Failed to compile. ./src/app/(auth)/signin/page.tsx Module not found: Can’t resolve ‘@/components/ui/card’ https://nextjs.org/docs/messages/module-not-found ./src/app/(auth)/signin/page.tsx Module not found: Can’t resolve ‘@/components/ui/input’ …
It has helped me
this solved it for me at least using vite, just changing the path in components and reinstalling
Thanks @alfinauzikri My issue is resolved.
You’re welcome. Glad to hear that the problem has been resolved… 😃
Thank you @alfinauzikri, saved me hours. Now it all makes sense putting the compiler options in the tsconfig file and extend it in the .app. Thank you again, hope it helps others as well.
vite.config.ts :
ts.config.json :
This is being split in 2 files from what I see by default, I did not do anything, and here is the tsconfig.app.json file :
I’ve put the same config in tsconfig.node.json file :
components.json:

Can you show me all the screenshots of these files?
@alfinauzikri I’ve created the project and followed the exact instructions as per : https://ui.shadcn.com/docs/installation/vite. Sorry if I’m repeating in this case something that other’s experienced, but in the shadcn installation docs, the resolve alias is set to ./src and the installation of shadcn goes in the root project, not in the src/folder .
Same thing with the tsconfig : “baseUrl”: “.”,
“paths”: {
“@/": [
"./src/”
]
} . I tried modifying paths to match the root folder, but still didn’t manage to find a solution 😦
hello i fixed it by deleting a tsconfig file but that also isn’t optimal