Next.js · build error
Module not found: Can't resolve '@/...' on deploy
verified on · Next.js 16.4.5 · React 19.3
Check yours: npm ls next react · On a different version? Paste your package.json into the free Doctor and it checks your versions against these fixes.
./src/app/page.tsx:1:1
Error: Module not found: Can't resolve '@/components/Header'
> 1 | import { Header } from "@/components/Header";
Import map: aliased to relative './src/components/Header' inside of [project]/What it means
The @/ alias comes from the paths setting in tsconfig.json (or jsconfig.json). Next.js swaps @/ for a real folder and then looks for that exact file. With Turbopack, the line under the error tells you which half broke. If it says Import map: aliased to relative './src/components/Header', the alias worked and that file is missing on the build machine, usually because of letter case or because git never got it. If there is no Import map line at all, Next.js never read your paths setting, so tsconfig.json is missing from the build or failed to parse. It works on your laptop because macOS and Windows ignore letter case by default and your local folder has every file. Vercel, Docker images and most CI runners build on Linux, which is case sensitive, and they only get what is in git.
Common causes
- Letter case. The file is header.tsx but the import says Header, or git still has the old name after you renamed it on a Mac. Linux treats them as two different files
- The file or folder was never committed. A line like lib/ in .gitignore (common in Python templates) also ignores src/lib at any depth
- paths points at the wrong folder, like "@/*": ["./*"] after the code moved into src/, so @/components looks in ./components
- tsconfig.json isn't in the build. A Dockerfile that copies only src/ and package.json, or a .dockerignore that leaves it out (no Import map line in the error)
- tsconfig.json extends a base config from another folder that the build can't see, so Next.js fails to parse it and the alias is gone (the build also prints An issue occurred while parsing a tsconfig.json file)
How to fix it
- Read the line under the error. Import map: aliased to relative './src/...' means look for that exact path. No Import map line means fix tsconfig.json first
- Run git ls-files src/components to see the exact case git has. If it differs, rename it with git mv (for example git mv src/components/header.tsx src/components/Header.tsx) or fix the import, then commit and push
- Run git check-ignore -v on the missing file. If a .gitignore line matches, change lib/ to /lib/ (root only) or remove it, then git add the folder
- Make paths match where the code lives. With a src folder it's "@/*": ["./src/*"], without one it's "@/*": ["./*"]
- Docker: copy tsconfig.json into the build stage before RUN npm run build (COPY . . with a .dockerignore that skips node_modules and .next is simplest)
- Before you push, build a fresh clone the way the server does: git clone . /tmp/check, then npm ci and npm run build in it. That catches files git doesn't have. On a Mac it won't catch case, so keep the git ls-files check
- Same error with a relative path like Can't resolve '../components/Header'? The paths and tsconfig.json steps don't apply. It's letter case or a file git doesn't have, so run the git ls-files and git check-ignore steps. TypeScript reports the same problem as Cannot find module '@/lib/db' or its corresponding type declarations (TS2307)
# 1. What exact name does git have? Linux builds are case sensitive.
git ls-files src/components | grep -i header
git mv src/components/header.tsx src/components/Header.tsx # if the case is wrong
# 2. Is the file ignored or never committed?
git check-ignore -v src/lib/site.ts
git status --short
# 3. Build what the server builds: a clean clone of what is committed
git clone . /tmp/check && cd /tmp/check && npm ci && npm run build
# tsconfig.json with a src folder:
# "paths": { "@/*": ["./src/*"] }Prompt for Cursor or Claude Code
My Next.js build fails on deploy with Module not found: Can't resolve '@/...' but works locally. Read the full error and tell me whether it has an Import map: aliased to relative line. If it does, check that exact path against git ls-files (exact letter case) and git check-ignore -v, and fix the import or rename the file with git mv. If it doesn't, check that tsconfig.json has paths "@/*" pointing at the folder my code is really in (./src/* if I use src), that any extends target exists in the repo, and that my Dockerfile or CI copies tsconfig.json before next build. Don't switch the imports to relative paths to hide it. List every file you changed.Not quite your error? Paste yours into the free VibeBoot Doctor or browse the Next.js error fixer.
Check your whole repo from the terminal: npx github:vibeboot/vibeboot-doctor (free, offline).
Upgrading from Next.js 15? The Next.js 16 upgrade checklist covers every breaking change, the error it causes and the fix.
next: skip the next one
Skip the setup. The VibeBoot SaaS Starter gives you auth, Stripe and a database already wired on Next.js 16, with AGENTS.md and .cursor/rules that keep your agent on the Next.js 16 conventions. $49, one-time.
14-day money-back guarantee · lifetime updates
Other Next.js errors
- useState / useEffect in a Server Component
- Event handlers cannot be passed to Client Component props
- Functions cannot be passed directly to Client Components
- Only plain objects can be passed to Client Components
- "use client" must be placed before other expressions
- export "metadata" from a "use client" page
$ fixed it? get the next one first
New fixes for what AI agents break, by email.
When we add a fix or a Cursor rule for a new Next.js, Auth.js, Prisma or Stripe break, it goes out in the VibeBoot newsletter. Free, occasional, unsubscribe in one click.