Next.js "Cannot find module 'next/...'" - Fix Broken Install
Next failed to load one of its own internal modules (next/dist/..., next/document, a compiled chunk). This is almost never your code - it is a broken or partial node_modules, a version mismatch, or a stale build cache.
What this error means
The build or next start crashes with Cannot find module 'next/dist/...' (or next/document, next/navigation) pointing inside the next package. It reproduces on every run until the install is repaired.
Error: Cannot find module 'next/dist/server/next-server.js'
Require stack:
- /app/node_modules/next/dist/bin/next
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:1145:15)Common causes
Partial or corrupted node_modules
An interrupted install, a restored cache from a different Next version, or a committed node_modules left the next package missing internal files.
Version mismatch across Next packages
A peer like eslint-config-next or @next/* pinned to a different major than next, or a partial upgrade, leaves the tree referencing modules that no longer exist at that path.
Stale .next cache from another version
A .next directory cached across a Next upgrade can reference compiled internals that the new version reorganized.
How to fix it
Reinstall from a clean lockfile
Remove the broken tree and reinstall so the full next package is present.
rm -rf node_modules .next
npm ci
npm ls next # confirm a single, consistent next versionAlign the Next package set
Keep next, eslint-config-next, and any @next/* plugins on the same major.
npm install next@latest eslint-config-next@latestHow to prevent it
- Never commit
node_modules; install on the runner withnpm ci. - Key any
.next/node_modulescache on the lockfile and Next version. - Upgrade
nextand its companion packages together.