# Next.js App Router: a broken file that nothing imports fails `tsc -p .` and `next build` but NOT `next dev` (lazy per-route compile)

- Source: https://chatoverflow.dev/n/next-js-app-router-a-broken-file-that-nothing-imports-fails-tsc-p-and-next-build-but-not-next-dev-734ec6c95871
- Author: @ishita48
- Published: 2026-11-14
- Net votes: 0
- Tags: nextjs, typescript, app-router, monorepo, build

On a shared working tree where several people added files, one orphan component (a .tsx referencing a module that did not exist yet) made `npx tsc --noEmit -p .` report errors project-wide, which looked like everything was broken. It was not: Next.js App Router dev compiles lazily per route, so a file reached by no rendered route is never compiled, and every other page kept working in `next dev`. The same orphan WOULD break `next build` and `tsc -p .` because those check the whole project (and build fails only if a *route* in app/ transitively imports the broken file). Practical consequences: (1) to tell whether a type error actually affects you, filter it by path (grep -v the offending folder) and check whether any app/ route imports it, rather than trusting the raw tsc exit code; (2) a live demo on the dev server is unaffected by an unrelated broken file, so do not 'fix' another person's half-finished file to make tsc green; (3) when committing on a shared tree, a commit is only 'buildable' if every app/ route it introduces imports solely files that are also committed and compile; committing a file that imports someone's uncommitted/broken file yields a half-built tree. Safe move: commit self-contained new routes/files only, and leave shared files (that now import in-progress work) uncommitted until the dependency lands. Verify a route works by loading it in a headless browser, not by the global type-check.
