[15.5] Reject TypeScript >= 7.0 with an actionable error (#96110)
## Summary
A minimal mitigation for the TypeScript 7 problem on the `15.5.x` line,
ported from the `next-16-2` mitigation (#95837).
TypeScript 7's native compiler no longer ships the JavaScript compiler
API (`typescript/lib/typescript.js`) that Next.js loads via
`require('typescript')`, so an installed TS7 produces surprising
failures with no actionable message. This was reported against 16.2 in
#95801.
## What it does
- Because the missing compiler-API file makes an installed TS7 look like
a *missing* dependency, `hasNecessaryDependencies` now also exposes the
resolved `typescript/package.json` path. `verifyTypeScriptSetup` reads
that version up front and, if it's `>= 7.0.0` (including prereleases —
`7.0.0-beta`/`-rc`, nightly `7.0.0-dev.*`, via the `7.0.0-0` sentinel
with `includePrerelease`), throws a `CompileError` with guidance to
install TypeScript 6 or upgrade Next.js, before the `require()` runs.
Unlike the 16.2 mitigation, no install-specifier change is needed here:
the `15.5` line already pins TypeScript auto-installs via
`getTypeScriptPackageSpec` (`typescript@5.8.2`) rather than pulling
`latest`.
Applies to both `next dev` and `next build`.
## Notes
- This is the minimal fix for `15.5`; the full
`experimental.useTypeScriptCli` backend (real TS7 support) is a
separate, larger effort and was considered overkill for this stable
line.
- Related: `next-16-2` mitigation #95837, and full backport #95831.
## Verification
- `pnpm --filter=next build`
- Boundary verified against the compiled semver: `5.8.2` / `6.x` (incl.
`6.0.0-beta`) are not rejected; `7.0.0-dev.*` / `7.0.0-beta` /
`7.0.0-rc` / `7.0.0` / `7.0.2` are rejected.
- Manual repro with `typescript@7` + `next@15.5`: `next build` and `CI=1
next build` exit non-zero with the actionable error instead of the
opaque failure.
Showing
Please
register
or
sign in
to comment