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-package

Check:

  • It's listed in package.json dependencies (not only installed globally)
  • You ran npm install in the right folder (monorepos often have several package.json files)
  • 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 dev

Fix 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"; // โœ…
Watch out: macOS and Windows file systems usually ignore letter case; Linux (which Vercel builds run on) doesn't. An import that works locally can fail in production. Also, Git may not record a rename that only changes case. Use 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:

flowchart LR CC["'use client' component"] --> U["utils.ts"] U --> DB["db.ts
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 devDependencies but needed at runtime โ†’ move it to dependencies
  • package-lock.json isn't committed or is out of date โ†’ commit it
  • A file is in .gitignore or .vercelignore โ†’ it never reached the build
  • Monorepo: the app's own package.json must list what it imports

Fix 6: Stale Caches

rm -rf .next node_modules/.cache
npm run dev

On 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

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.