[16.2] Reject TypeScript >= 7.0 with an actionable error (mitigation for #95801) - #95837
Closed
lukesandberg wants to merge 2 commits into
Closed
[16.2] Reject TypeScript >= 7.0 with an actionable error (mitigation for #95801)#95837lukesandberg wants to merge 2 commits into
lukesandberg wants to merge 2 commits into
Conversation
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.
Contributor
Failing CI jobsCommit: 69a3067 | About building and testing Next.js |
Contributor
Stats skippedCommit: 69a3067 |
lukesandberg
marked this pull request as ready for review
July 16, 2026 01:39
lukesandberg
force-pushed
the
mitigation-reject-typescript-7-next-16-2
branch
from
July 16, 2026 02:06
c9fb14f to
69a3067
Compare
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.
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A minimal mitigation for #95801, where
next build/next devcrash with a silentSIGSEGV/SIGABRTon the16.2.xline whentypescript@7is installed. TypeScript 7's native compiler no longer ships the JavaScript compiler API (typescript/lib/typescript.js) that Next.js loads viarequire('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
typescriptpackage.jsonversion is checked up front. If it's>= 7.0.0, throw aCompileErrorwith 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 crashingrequire().typescript@^6.0.0(via a new optionalinstallspecifier onMissingDependency) instead of pullinglatest, which is TS7.Applies to both
next devandnext build.Fixes
Fixes #95801
Verification
pnpm --filter=next buildtypescript@7.0.2project (seenext build(16.2.x, Turbopack) crashes with a silent SIGSEGV/SIGABRT when typescript@7 is installed andtypescript.ignoreBuildErrors: trueis set in CI — please backport the graceful error from canary #95801):next buildandCI=1 next buildnow exit non-zero with the actionable error and noSIGSEGV/SIGABRT, and no longer churn through a pointless reinstall of the unsupported version first.typescriptremoved from the project, the auto-install now pulls the v6 range and the build succeeds.