Skip to content
Latchkey

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.

next output
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.

Terminal
rm -rf node_modules .next
npm ci
npm ls next   # confirm a single, consistent next version

Align the Next package set

Keep next, eslint-config-next, and any @next/* plugins on the same major.

Terminal
npm install next@latest eslint-config-next@latest

How to prevent it

  • Never commit node_modules; install on the runner with npm ci.
  • Key any .next/node_modules cache on the lockfile and Next version.
  • Upgrade next and its companion packages together.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →