Fix guides · Cursor, v0, Lovable, Bolt ·

Fix Can't resolve '@/components/ui/button'

Module not found: Can't resolve '@/components/ui/button'

This error means the bundler (the tool that packages your code, such as Next.js's webpack or Turbopack) looked for '@/components/ui/button' and found no file there. Usually the shadcn/ui Button component was never added to the project, or the '@/' shortcut (a path alias) isn't configured to point at the folder that holds your components. Adding the component with `npx shadcn@latest add button`, or fixing the alias in tsconfig.json (and vite.config for Vite apps), fixes most cases.

Free · 3 a day · no signup

Common causes – and how to tell which one you have

1. The Button component was never added

How to tell: There is no button.tsx in components/ui/ or src/components/ui/. This is common when code was copied from v0 or an AI chat into a project that doesn't have shadcn/ui set up.

Fix: shadcn/ui copies component source files into your project instead of installing them as a package. Run `npx shadcn@latest add button`. If the CLI says components.json is missing, run `npx shadcn@latest init` first.

2. The @/ alias is missing or points to the wrong folder

How to tell: button.tsx exists, but tsconfig.json (or jsconfig.json) has no "paths" entry for "@/*", or the entry points to ./src/* while your components folder is at the project root, or the other way round.

Fix: Under compilerOptions in tsconfig.json, set "paths": { "@/*": ["./src/*"] } if components/ is inside src/, or ["./*"] if it is at the root. Then restart the dev server.

3. Vite app has no matching alias in vite.config

How to tell: The project is Vite-based (common in Lovable and Bolt), tsconfig paths look correct, and the dev overlay says something like 'Failed to resolve import "@/components/ui/button"'.

Fix: Vite doesn't read tsconfig paths by default. Add resolve.alias with "@": path.resolve(__dirname, "./src") in vite.config.ts, as the shadcn/ui Vite install docs show. Also add the paths entry to tsconfig.app.json if your template has one.

4. Works locally, fails on deploy (case or git)

How to tell: The app runs on your Mac or Windows machine but the Vercel/Netlify build fails. The file is named Button.tsx instead of button.tsx, or it was never committed to git.

Fix: Rename the file so its case matches the import exactly. On case-insensitive systems use `git mv Button.tsx temp.tsx` then `git mv temp.tsx button.tsx`. Confirm the file appears in your GitHub repo, then redeploy.

5. shadcn installed components to a different folder

How to tell: button.tsx exists, but somewhere other than where the import expects, for example src/components/ui while the alias maps to the root. components.json shows the aliases shadcn uses.

Fix: Make the aliases in components.json, tsconfig paths, and the real folder all agree. Either move the components folder or update the alias. Don't change every import to match a misplaced folder.

How to fix it

  1. Look for button.tsx in components/ui/ and src/components/ui/. Note which folder your project uses for code (root or src).
  2. If the file is missing, check for components.json at the project root. If it's not there, run `npx shadcn@latest init`.
  3. Run `npx shadcn@latest add button` and confirm components/ui/button.tsx now exists, along with lib/utils.ts if it wasn't there already.
  4. Open tsconfig.json (or jsconfig.json) and make sure compilerOptions.paths has "@/*" pointing to the folder that contains components: ["./src/*"] or ["./*"].
  5. For a Vite project, add resolve.alias { "@": path.resolve(__dirname, "./src") } in vite.config.ts. Add the same paths entry to tsconfig.app.json if it exists.
  6. Check that the filename is exactly button.tsx in lowercase and that it is committed to git.
  7. Stop and restart the dev server, then run the production build to confirm the error is gone.

Using Lovable, Bolt or v0?

In Lovable or Bolt, tell the tool: "The build fails because src/components/ui/button.tsx is missing. Add the standard shadcn/ui Button component and any dependencies it needs, and make sure the @/ alias in vite.config.ts and tsconfig points to src." Then open the file tree and confirm button.tsx is there with a lowercase name. If you deploy through Vercel or Netlify, check the build log and your connected GitHub repo to confirm the file was actually committed. For v0 code you move into your own project, use the install or add-to-codebase option v0 offers, which runs the shadcn CLI and brings the components along.

Using Cursor, Claude Code or Windsurf?

Ask Cursor or Claude Code to first show you whether components/ui/button.tsx exists and print the paths section of tsconfig.json, components.json, and the resolve.alias in vite.config if it's a Vite app, before changing anything. If the file is missing, have it run `npx shadcn@latest add button` instead of writing a Button by hand. Ask it to restart the dev server and run the production build (for example `npm run build`), then paste the output. Don't accept "this should work now" without a passing build.

The “fix” to avoid

Agents often 'fix' this by writing a quick placeholder Button, swapping in a plain <button>, or changing one import to a long relative path like '../../components/ui/button'. The error goes away for that one file, but the other shadcn components and imports stay broken, and a hand-written Button usually lacks the variant and size props the rest of the code expects. Adding // @ts-ignore also does nothing here, because the bundler fails, not just TypeScript.

Copy-paste fix prompt for your AI coding tool

Paste this into Cursor, Claude Code, Lovable or Bolt:

My build fails with: Module not found: Can't resolve '@/components/ui/button'. Before editing anything, check these in order and report what you find: 1) Does components/ui/button.tsx or src/components/ui/button.tsx exist with that exact lowercase name? 2) Does components.json exist? 3) What does compilerOptions.paths in tsconfig.json (and tsconfig.app.json if present) map "@/*" to, and does that match the real folder? 4) If this is a Vite app, does vite.config have a resolve.alias for "@"? If the file is missing, run `npx shadcn@latest add button` (run `npx shadcn@latest init` first if components.json is missing). Don't hand-write a placeholder. If the file exists, fix the alias so tsconfig, vite.config, and components.json all point to the same folder. Don't switch imports to relative paths. Then restart the dev server, run the production build, and show me the output proving it passes.
Your error looks a bit different? Paste your exact error and get a diagnosis tailored to your code — free.

Questions people ask

Why does it work locally but fail on Vercel?

Vercel builds on Linux, where filenames are case-sensitive, so Button.tsx won't match an import of 'button'. The file may also exist on your machine but never have been committed to git. Fix the filename case, commit the file, and redeploy.

Can I just run npm install shadcn to fix it?

No. shadcn/ui isn't a library you import from node_modules. Its CLI copies each component's source code into your project. Use `npx shadcn@latest add button` to create the missing file.

What does the @/ in the import mean?

It's a path alias, a shortcut you configure in tsconfig.json (and vite.config for Vite) that usually means 'the src folder' or 'the project root'. If the alias isn't configured or points to the wrong folder, every '@/' import fails, even when the file exists.

Official documentation

Related errors

Get fixes like this every week