The Error
Your Next.js app fails to build or start with:
Module not found: Can't resolve 'some-package'
Module not found: Can't resolve '@/components/Button'
Module not found: Can't resolve 'fs'The bundler (Turbopack or Webpack) followed an import and couldn't find the file or package. The fix depends on what it can't resolve: a package, a local file, an alias, or a Node.js built-in.
๐ฏ Quick Diagnosis
| What can't be resolved | Most likely cause | Jump to |
|---|---|---|
'some-package' |
Not installed, or installed in a different folder | Fix 1 |
'./components/button' |
Wrong path or wrong letter case | Fix 2 |
'@/lib/db' |
Path alias not configured | Fix 3 |
'fs', 'path', 'crypto' |
Node module imported into client code | Fix 4 |
| Works locally, fails on Vercel | Case sensitivity or a missing dependency | Fixes 2 and 5 |
Fix 1: The Package Isn't Installed
npm install some-packageCheck:
- It's listed in
package.jsondependencies (not only installed globally) - You ran
npm installin the right folder (monorepos often have severalpackage.jsonfiles) - The package name is spelled exactly right, including scope (
@scope/name)
If it still fails, clear and reinstall:
rm -rf node_modules .next
npm install
npm run devFix 2: Wrong Path or Letter Case
// file on disk: components/Button.tsx
import Button from "./components/button"; // โ works on macOS/Windows, fails on Linux/Vercel
import Button from "./components/Button"; // โ
git mv button.tsx Button.tsx to make it stick.
Also check relative paths: ../ vs ./, and whether the file was moved.
Fix 3: Path Aliases (@/...)
@/components/Button only works if the alias is configured in tsconfig.json (or jsconfig.json):
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"]
}
}
}Make sure the target matches your structure: ./src/* if your code is in src/, or ./* if it isn't. Restart the dev server after changing it.
Fix 4: Node.js Modules in Client Code
Module not found: Can't resolve 'fs'Browsers don't have fs, path or child_process. This error usually means a Client Component (or something it imports) uses a server-only module:
imports 'fs' / 'pg'"] DB -.->|"bundled for browser"| X["โ Can't resolve 'fs'"]
Fixes:
- Move the server-only code into a Server Component, Route Handler or Server Action
- Add
import "server-only";to server modules so mistakes fail with a clear error - Split shared helpers so client code doesn't import files that pull in Node modules
Fix 5: Dependencies Missing in Production
If it works locally but fails in CI or on Vercel:
- The package is in
devDependenciesbut needed at runtime โ move it todependencies -
package-lock.jsonisn't committed or is out of date โ commit it - A file is in
.gitignoreor.vercelignoreโ it never reached the build - Monorepo: the app's own
package.jsonmust list what it imports
Fix 6: Stale Caches
rm -rf .next node_modules/.cache
npm run devOn Vercel, redeploy without the build cache from the deployment's menu.
Frequently Asked Questions
Why does my Next.js app build locally but fail on Vercel with Module not found?
The most common cause is letter case: macOS and Windows ignore case in file names but Linux build servers don't, so an import with the wrong case fails only on Vercel. Other causes are packages missing from dependencies, uncommitted lockfiles, or ignored files.
How do I fix Module not found: Can't resolve 'fs' in Next.js?
The fs module only exists on the server. Make sure code using fs runs in Server Components, Route Handlers or Server Actions, not in Client Components or files they import. Adding import "server-only" to server modules helps catch these mistakes.
Why is the @/ import alias not working?
The alias must be defined in tsconfig.json or jsconfig.json under compilerOptions.paths, pointing to the right folder, such as ./src/* or ./*. Restart the development server after changing it.
Conclusion
"Module not found: Can't resolve" means the bundler couldn't follow an import. Install missing packages, fix paths and letter case (especially for Linux builds), configure @/ aliases in tsconfig, keep Node-only modules out of client code, and clear stale caches.
Sources
- Next.js docs: Module not found
- Next.js docs: Absolute imports and module path aliases
- Next.js docs: Server and Client Components (server-only)
Last verified: 2 November 2026.
Related reads: Fix Next.js Hydration Error ยท Fix npm ERESOLVE ยท Fix Vercel Function Timeout ยท How to Deploy Next.js on Vercel
I write practical guides for developers. Follow on LinkedIn or X, or invite me to speak.