Module not found on Vercel but the build passes on my machine
Module not found: Can't resolveShort 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.
Fix it fast
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"2Match what you see, then jump to its fix
- 1
Module not found: Can't resolve './components/header' while the file is Header.tsxFile name casing differs between the import and the fileFix - 2
The unresolved path is a package name, not a relative pathA package is imported but not listed in package.jsonFix - 3
The path has several ../ segments or an alias like @/A relative path or alias only works on your machineFix
- 1
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.tsx3Verify
Commit, push and redeploy, then read the new build log.
git commit -m "Fix file name casing"
git pushConfirmed by vercel.com
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.json2Fix
Install it so it is saved to package.json, then commit package.json and the lockfile.
npm install the-package-name3Verify
Redeploy and check the build log.
git status --short package.json package-lock.jsonConfirmed by vercel.com
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 buildConfirmed by vercel.com
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
Web apps
AuthUserPoolException: Auth UserPool not configured in a Next.js app
Auth UserPool not configured
The error means an Amplify Auth call ran before Amplify.configure did.
3 causes, each with a fixWeb apps
Apollo Server rejects a request as a potential CSRF
HTTP 400 Bad Request from the GraphQL endpoint
Apollo Server's CSRF prevention is on by default.
3 causes, each with a fixWeb apps
Clerk cannot read its publishable key in a Next.js app
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY is undefined
Clerk reads NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY.
3 causes, each with a fixWeb apps
The shell cannot find create-next-app
command not found: create-next-app
create-next-app is not meant to be installed as a shell command.
2 causes, each with a fixWeb apps
ESLint fails with: Cannot find module 'next/babel'
ESLint stops on the first file with a Babel or parser error instead of listing lint results
next/babel is a Babel preset that ships inside the next package.
3 causes, each with a fixWeb apps
ESLint says an element in a list is missing its key prop
react/jsx-key
react/jsx-key fires when an element returned from map, Array.from or an array literal has no key.
3 causes, each with a fix