Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Next.js and React

Module not found on Vercel but the build passes on my machine

ErrorModule not found: Can't resolve

Short answer

Vercel builds on Linux, which treats Header.tsx and header.tsx as different files. Windows and macOS usually do not. Compare the path in the build log with the real file name in Git, fix the casing, and rename through a temporary name so Git records it. Also confirm that every imported package is in package.json.

  • Applies to Next.js 15, Next.js 16, Vercel
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Open the failed deployment's build log and copy the path from the Module not found line. Compare it character by character with what Git tracks.

    git ls-files | grep -i "header"
  2. 2Match what you see, then jump to its fix

    1. 1Module not found: Can't resolve './components/header' while the file is Header.tsxFile name casing differs between the import and the fileFix
    2. 2The unresolved path is a package name, not a relative pathA package is imported but not listed in package.jsonFix
    3. 3The path has several ../ segments or an alias like @/A relative path or alias only works on your machineFix

What does the error look like?

  • Module not found: Can't resolve

Cause 1 of 3

File name casing differs between the import and the file

1Check

List what Git really tracks. A rename that only changed letter case may never have been recorded.

git ls-files components/

2Fix

Make the import and the file name use the same casing. If Git missed a case-only rename, tell Git to notice case changes and rename through a temporary name, then commit both steps together.

git config core.ignorecase false
git mv header.tsx header-tmp.tsx
git mv header-tmp.tsx Header.tsx

3Verify

Commit, push and redeploy, then read the new build log.

git commit -m "Fix file name casing"
git push

Confirmed by vercel.com

Did this fix it?

Cause 2 of 3

A package is imported but not listed in package.json

1Check

A package installed only on your machine, or never committed to package.json, is not installed on Vercel.

grep -n "the-package-name" package.json

2Fix

Install it so it is saved to package.json, then commit package.json and the lockfile.

npm install the-package-name

3Verify

Redeploy and check the build log.

git status --short package.json package-lock.json

Confirmed by vercel.com

Did this fix it?

Cause 3 of 3

A relative path or alias only works on your machine

1Check

Count the ../ segments against the real folder depth. A path alias can resolve in your editor but fail on a clean checkout.

git ls-files | grep -i "lib/utils"

2Fix

Correct the relative path, or make sure the alias is defined in the committed tsconfig.json or jsconfig.json.

// tsconfig.json
{ "compilerOptions": { "paths": { "@/*": ["./*"] } } }

3Verify

Build from a clean clone to copy what Vercel does.

git clone . ../clean-check && cd ../clean-check
npm ci && npm run build

Confirmed by vercel.com

Did this fix it?

How do I stop it coming back?

  • Run git config core.ignorecase false on Windows and macOS clones.
  • Name files with one convention, such as PascalCase for components, and keep it.
  • Run a clean-clone build in CI before merging.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.