Skip to content

[16.2] Reject TypeScript >= 7.0 with an actionable error (mitigation for #95801) - #95837

Closed
lukesandberg wants to merge 2 commits into
next-16-2from
mitigation-reject-typescript-7-next-16-2
Closed

[16.2] Reject TypeScript >= 7.0 with an actionable error (mitigation for #95801)#95837
lukesandberg wants to merge 2 commits into
next-16-2from
mitigation-reject-typescript-7-next-16-2

Conversation

@lukesandberg

Copy link
Copy Markdown
Contributor

Summary

A minimal mitigation for #95801, where next build / next dev crash with a silent SIGSEGV/SIGABRT on the 16.2.x line when typescript@7 is installed. TypeScript 7's native compiler no longer ships the JavaScript compiler API (typescript/lib/typescript.js) that Next.js loads via require('typescript'), so loading it kills the process with no actionable message.

This is an alternative to the full backport in #95831. Rather than backporting the experimental TypeScript CLI backend (and its prerequisites), it makes the unsupported case fail cleanly. The two are mutually exclusive: ship this now for a quick, low-risk fix, or take #95831 for actual TS7 support via experimental.useTypeScriptCli.

What it does

  • TS7 already installed — because the missing compiler-API file makes an installed TS7 look like a missing dependency, the resolved typescript package.json version is checked up front. If it's >= 7.0.0, throw a CompileError with guidance to install TypeScript 6 or upgrade Next.js. This runs before the auto-install path (so we don't reinstall the unsupported version) and before the crashing require().
  • TypeScript absent entirely — pin the auto-install to typescript@^6.0.0 (via a new optional install specifier on MissingDependency) instead of pulling latest, which is TS7.

Applies to both next dev and next build.

Fixes

Fixes #95801

Verification

TypeScript 7's native compiler no longer ships the JavaScript compiler API
(`typescript/lib/typescript.js`) that Next.js loads via `require('typescript')`.
Loading it crashes the build worker with a silent SIGSEGV/SIGABRT and no
actionable message.

Two cases are handled:

- When TS7 is already installed, the missing API file makes it look like a
  missing dependency. Check the resolved `typescript` package version up front
  and throw a CompileError with guidance to install TypeScript 6 or upgrade
  Next.js. This runs before the auto-install path (so we don't reinstall the
  unsupported version) and before the crashing `require()`.
- When TypeScript is absent entirely, pin the auto-install to `typescript@^6.0.0`
  via a new optional `install` specifier on MissingDependency, instead of
  pulling `latest` (which is TS7).

Temporary mitigation for the 16.2.x line; an alternative to the experimental
TypeScript CLI backend backport.
@github-actions

github-actions Bot commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Failing CI jobs

Commit: 69a3067 | About building and testing Next.js

@github-actions

github-actions Bot commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Stats skipped

Commit: 69a3067
View workflow run

@lukesandberg
lukesandberg requested a review from eps1lon July 16, 2026 01:39
@lukesandberg
lukesandberg marked this pull request as ready for review July 16, 2026 01:39
Comment thread packages/next/src/lib/verify-typescript-setup.ts Outdated
@lukesandberg
lukesandberg force-pushed the mitigation-reject-typescript-7-next-16-2 branch from c9fb14f to 69a3067 Compare July 16, 2026 02:06
lukesandberg added a commit that referenced this pull request Jul 24, 2026
## 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant