Fix Cannot find name 'LayoutProps' in npm run typecheck
#1
by arshvinw5 - opened
Problem
tsc --noEmit failed on a clean checkout with:
src/app/layout.tsx(27,50): error TS2304: Cannot find name 'LayoutProps'.
In Next 16, LayoutProps is a global helper that isn't imported. Next generates it into /types/routes.d.ts during next dev, next build or next typegen. The typecheck script ran bare tsc, so it only passed on machines that already had generated types left over from an earlier next dev run.
The tracked next-env.d.ts made this worse. It pointed at .next/types/... (the build path), but next dev rewrites it to .next/dev/types/.... The file kept showing up as modified, and it referenced files that don't exist on a fresh clone.
Changes
- package.json: typecheck is now next typegen && tsc --noEmit, which generates the route types before type-checking. This is the pattern the Next docs recommend.
- .gitignore / next-env.d.ts: stop tracking next-env.d.ts and add it to .gitignore. The Next docs say it's a generated file that shouldn't be committed. next typegen, dev and build all recreate it.
- No change to src/app/layout.tsx. The code is correct, and adding an import would be wrong because the type is global.
Testing
- Deleted .next and next-env.d.ts to simulate a clean checkout. Bare tsc --noEmit reproduced the error.
- npm run typecheck from the same clean state exits 0. It generates .next/types/routes.d.ts and next-env.d.ts.
- npm run build succeeds.
- next-env.d.ts no longer shows up as modified in git status.
Notes
- Anyone who pulls this will have next-env.d.ts removed from tracking. Their local copy stays on disk and is regenerated as needed.
- If CI runs tsc directly, switch it to npm run typecheck.