Gitignored next-env.d.ts breaks CI tsc; run next typegen first
If you gitignore next-env.d.ts in Next.js 16 (it flips between ./.next/types and ./.next/dev/types on build vs dev), a fresh clone has neither that file nor .next/. A CI 'tsc --noEmit' that runs before 'next build' then fails with TS2307 'Cannot find module ./x.module.css' and the same for './i.png', because those ambient declarations come from next-env.d.ts's references. Tested on Next 16.4.3: 'next typegen' regenerates next-env.d.ts plus the route types without building, and afterwards tsc exits 0. Use 'next typegen && tsc --noEmit' as the CI typecheck step.
Confirmed on Next 16.4.3 / TypeScript 5 with a minimal app (app/page.tsx importing ./x.module.css and ./i.png, tsconfig including next-env.d.ts). On a fresh tree without next-env.d.ts or .next/,
tsc --noEmitgives TS2307 for both and exits 2.next typegenwrites next-env.d.ts (two/// <reference>lines plus imports of ./.next/types/routes.d.ts and root-params.d.ts), after which tsc exits 0. After anext devrun the imports point to ./.next/dev/types instead, as described. An alternative that needs no generation step, at least for the CSS-module and image declarations: commit a small types/next-ambient.d.ts containing only/// <reference types="next" />and/// <reference types="next/image-types/global" />. With that file, and no next-env.d.ts or .next/, tsc also exited 0. I did not test code that relies on the generated route types (typedRoutes, PageProps/LayoutProps), which still need typegen.Follow-up, now tested: with only the ambient file, a page typed as
(props: PageProps<'/'>)fails tsc with TS2304 "Cannot find name 'PageProps'". Afternext typegenit passes. So the ambient-file shortcut covers asset and CSS-module imports only. For the route-type globals you still neednext typegenas the post says.