Skip to content

Fix termination handling - #95692

Merged
lukesandberg merged 3 commits into
canaryfrom
lukesandberg/ts-cli-followups
Jul 13, 2026
Merged

Fix termination handling#95692
lukesandberg merged 3 commits into
canaryfrom
lukesandberg/ts-cli-followups

Conversation

@lukesandberg

@lukesandberg lukesandberg commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Follow-ups for the experimental TypeScript CLI checker

Two independent improvements to the experimental.useTypeScriptCli build path.

1. Make tsc responsive to interruption

When next build is interrupted (Ctrl-C / SIGTERM), the TypeScript 7 native compiler could keep running to completion instead of stopping — leaving a CPU-heavy process alive after the build was abandoned.

The teardown already handled termination signals and killed the whole process group; the problem was the signal it sent. The native compiler ignores SIGTERM/SIGINT, so the graceful signal never stopped it. We now escalate to SIGKILL (Windows: taskkill /T /F), which reaps the compiler on interrupt (measured ~200ms vs. running to completion).

The compiler's signal handling may be improved upstream — see microsoft/typescript-go#4592, in the mean time we should just send a kill signal

2. Skip the jest worker for the CLI checker

The type-check runs in a jest worker to isolate the TypeScript compiler-API heap so it can be freed after checking. In CLI mode the compiler runs in a separate tsc process, so there is no heap to isolate. Just spawn tsc from the parent process.

Testing

  • Unit tests for runTypeScriptCli (spawn options, group-SIGKILL teardown, signal handling, listener cleanup, captured-output decoding).
  • Existing test/production/app-dir/typescript-cli integration suite passes (TS 6, TS 7, opt-in-required, ignoreBuildErrors, --debug-build-paths).
  • Manually verified against a TypeScript 7 project large enough to distinguish a real kill from natural completion: the native compiler is reaped ~200ms after interrupt.

Copy link
Copy Markdown
Contributor Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@github-actions

github-actions Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Tests Passed

Commit: 946e81f

@github-actions

github-actions Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Stats from current PR

🔴 4 regressions

Metric Canary PR Change Trend
Turbo Build Time 4.989s 5.569s 🔴 +580ms (+12%) ▁▂█▃▁
Turbo Build Time (cached) 5.157s 5.615s 🔴 +458ms (+9%) ▁▂▇▃▁
Webpack Build Time (cached) 25.036s 25.563s 🔴 +527ms (+2%) ▂▁▁▁▂
Webpack Warm (First Request) 3.344s 3.480s 🔴 +136ms (+4%) ▁▁▁▁▂
📊 All Metrics
📖 Metrics Glossary

Dev Server Metrics:

  • Listen = TCP port starts accepting connections
  • First Request = HTTP server returns successful response
  • Cold = Fresh build (no cache)
  • Warm = With cached build artifacts

Build Metrics:

  • Fresh = Clean build (no .next directory)
  • Cached = With existing .next directory

Change Thresholds:

  • Time: Changes < 50ms AND < 10%, OR < 2% are insignificant
  • Size: Changes < 1KB AND < 1% are insignificant
  • All other changes are flagged to catch regressions

⚡ Dev Server

Metric Canary PR Change Trend
Cold (Listen) 813ms 813ms ▁▂▇▂▁
Cold (Ready in log) 782ms 782ms ▁▁█▂▁
Cold (First Request) 1.292s 1.307s ▁▁█▂▁
Warm (Listen) 813ms 812ms ▁▁█▂▂
Warm (Ready in log) 781ms 783ms ▁▁█▂▁
Warm (First Request) 1.287s 1.305s ▂▂█▁▁
📦 Dev Server (Webpack) (Legacy)

📦 Dev Server (Webpack)

Metric Canary PR Change Trend
Cold (Listen) 814ms 812ms ▂▂▂▂▂
Cold (Ready in log) 780ms 794ms ▁▁▂▁▂
Cold (First Request) 3.361s 3.454s ▂▂▂▁▂
Warm (Listen) 812ms 812ms ▂▂▂▂▂
Warm (Ready in log) 781ms 791ms ▁▂▁▁▂
Warm (First Request) 3.344s 3.480s 🔴 +136ms (+4%) ▁▁▁▁▂

⚡ Production Builds

Metric Canary PR Change Trend
Fresh Build 4.989s 5.569s 🔴 +580ms (+12%) ▁▂█▃▁
Cached Build 5.157s 5.615s 🔴 +458ms (+9%) ▁▂▇▃▁
📦 Production Builds (Webpack) (Legacy)

📦 Production Builds (Webpack)

Metric Canary PR Change Trend
Fresh Build 24.663s 24.878s ▂▂▂▁▂
Cached Build 25.036s 25.563s 🔴 +527ms (+2%) ▂▁▁▁▂
node_modules Size 516 MB 516 MB █████
📦 Bundle Sizes

Bundle Sizes

⚡ Turbopack

Client

Main Bundles
Canary PR Change
03gmyxr7dukvs.js gzip 10.3 kB N/A -
03kxtldm3sk2x.js gzip 153 B N/A -
040t1q17lo593.js gzip 8.77 kB N/A -
0bb0vtp8dwsez.js gzip 450 B N/A -
0cz1d0mv5g_q7.js gzip 39.4 kB 39.4 kB
0d9_sdfmlgx3x.js gzip 156 B N/A -
0e985y33y--az.js gzip 45.8 kB N/A -
0ghtcd3-0src1.js gzip 157 B N/A -
0gvibj29i-u0w.js gzip 157 B N/A -
0l0sr6gau5xjn.js gzip 3.53 kB N/A -
0nxqz3q165m2l.js gzip 220 B N/A -
0qr-1tnb7_hg5.js gzip 5.72 kB N/A -
0uilzvklme4ea.js gzip 8.76 kB N/A -
0z0y83mfx-l-h.js gzip 10 kB N/A -
15ok8ydf274z0.js gzip 10.6 kB N/A -
16cqqcigykfea.js gzip 13.6 kB N/A -
17h18zxt1915l.js gzip 1.46 kB N/A -
1elt1qium-r2m.css gzip 115 B 115 B
1fq1h7dxad4cv.js gzip 9.44 kB N/A -
1fym-adbk_69_.js gzip 13.1 kB N/A -
1g80-jfls9qyr.js gzip 13.2 kB N/A -
1gav7nfh4y8ln.js gzip 8.76 kB N/A -
1ljh0cxv8ewm7.js gzip 156 B N/A -
1w8vqo51u2z7m.js gzip 155 B N/A -
256hcvivlx119.js gzip 155 B N/A -
26xnr0078vuee.js gzip 71.1 kB N/A -
28ligxg2pcqgb.js gzip 153 B N/A -
2jh0hejcskd4k.js gzip 162 B N/A -
2rypqffktcxqh.js gzip 8.69 kB N/A -
2uqsizxtehgqf.js gzip 8.79 kB N/A -
2vzktdqwbijqc.js gzip 8.74 kB N/A -
2ywt5-44-_nz7.js gzip 160 B N/A -
2zkqm4tctb0gx.js gzip 167 B N/A -
36wjeu1dua7he.js gzip 156 B N/A -
38ipdetrk9ucb.js gzip 157 B N/A -
3c244akvx_-be.js gzip 8.74 kB N/A -
3dmlemitx3ef3.js gzip 2.29 kB N/A -
3duqgr_j37bji.js gzip 65.6 kB N/A -
3y193x4n8cq9d.js gzip 7.4 kB N/A -
4237vdj6eyslt.js gzip 8.7 kB N/A -
turbopack-0_..vf3q.js gzip 3.86 kB N/A -
turbopack-0w..ldhz.js gzip 3.85 kB N/A -
turbopack-1e..9rsa.js gzip 3.85 kB N/A -
turbopack-1v..y-5d.js gzip 3.85 kB N/A -
turbopack-1v..hah-.js gzip 3.85 kB N/A -
turbopack-2c..me-e.js gzip 3.85 kB N/A -
turbopack-2f..t0ne.js gzip 3.85 kB N/A -
turbopack-2m..jwnj.js gzip 3.85 kB N/A -
turbopack-2o..gr3q.js gzip 3.83 kB N/A -
turbopack-2r..p_fq.js gzip 3.85 kB N/A -
turbopack-2y..v7d3.js gzip 3.85 kB N/A -
turbopack-3r..j6m5.js gzip 3.85 kB N/A -
turbopack-3w.._6ov.js gzip 3.85 kB N/A -
turbopack-3z..-lp0.js gzip 3.85 kB N/A -
00tc16j5-eos9.js gzip N/A 1.46 kB -
05tax4x1rfda4.js gzip N/A 7.4 kB -
0f3x8hscjb7ap.js gzip N/A 156 B -
0gaw1gmpwuwkn.js gzip N/A 8.8 kB -
0v19i0q8g4rho.js gzip N/A 156 B -
12zyjjmq4oad1.js gzip N/A 5.72 kB -
17v7o0y0g4-7-.js gzip N/A 155 B -
1k9cc4-gpa2cx.js gzip N/A 13.1 kB -
1n59uogejo81s.js gzip N/A 10.3 kB -
1noy5y6bnyiy7.js gzip N/A 154 B -
1npei3hlexdv3.js gzip N/A 9.99 kB -
1ssuiwj_rnpc5.js gzip N/A 8.77 kB -
1uqman5iy_ejn.js gzip N/A 156 B -
2-phc9obd3nyd.js gzip N/A 8.77 kB -
24utq57r3l1cw.js gzip N/A 8.7 kB -
2a3jkn8z7ke-t.js gzip N/A 65.6 kB -
2fhjq6ek3srmr.js gzip N/A 8.69 kB -
2g0t7upz_v-hf.js gzip N/A 10.6 kB -
2ghzkgx1ddgu_.js gzip N/A 157 B -
2ia9qqy99aie9.js gzip N/A 13.6 kB -
2koxg04ry-g8s.js gzip N/A 168 B -
2m-y5z-jn6d95.js gzip N/A 155 B -
2oza28kdqvoay.js gzip N/A 8.74 kB -
2zh8-mmhujy8o.js gzip N/A 2.29 kB -
30h_m0irj-q6p.js gzip N/A 221 B -
319hk3fl01uhk.js gzip N/A 71.1 kB -
37ejbfx1u9lpo.js gzip N/A 8.75 kB -
38c63ct4i1cy7.js gzip N/A 449 B -
38i6xpn0ullxe.js gzip N/A 155 B -
3hd1us4ordyc9.js gzip N/A 13.2 kB -
3jimpal3lvz5e.js gzip N/A 9.44 kB -
3olzqw8v8kq4p.js gzip N/A 160 B -
3otxp6kbeequz.js gzip N/A 156 B -
3su6a4l8jbfth.js gzip N/A 3.53 kB -
3w25ccsfocdnd.js gzip N/A 159 B -
3wb4pe4z4-aim.js gzip N/A 8.77 kB -
40j0uuoh0xxc2.js gzip N/A 155 B -
40k6sbmro-wy8.js gzip N/A 45.8 kB -
turbopack-05..ztdo.js gzip N/A 3.85 kB -
turbopack-05..tsib.js gzip N/A 3.85 kB -
turbopack-12..zapb.js gzip N/A 3.85 kB -
turbopack-19..g7-6.js gzip N/A 3.85 kB -
turbopack-1y..7z80.js gzip N/A 3.83 kB -
turbopack-2i..cubw.js gzip N/A 3.86 kB -
turbopack-2v..f86f.js gzip N/A 3.85 kB -
turbopack-2w..l3g5.js gzip N/A 3.85 kB -
turbopack-2x..mykf.js gzip N/A 3.85 kB -
turbopack-2x..xsyd.js gzip N/A 3.85 kB -
turbopack-3_..obhu.js gzip N/A 3.85 kB -
turbopack-35..p4jp.js gzip N/A 3.85 kB -
turbopack-3f..ggdw.js gzip N/A 3.85 kB -
turbopack-3o..gklp.js gzip N/A 3.85 kB -
Total 449 kB 449 kB ⚠️ +43 B

Server

Middleware
Canary PR Change
middleware-b..fest.js gzip 732 B 726 B
Total 732 B 726 B ✅ -6 B
Build Details
Build Manifests
Canary PR Change
_buildManifest.js gzip 432 B 436 B
Total 432 B 436 B ⚠️ +4 B

📦 Webpack

Client

Main Bundles
Canary PR Change
2486.HASH.js gzip 169 B N/A -
3146-HASH.js gzip 64 kB N/A -
39fcf99b-HASH.js gzip 62.9 kB N/A -
8443-HASH.js gzip 4.68 kB N/A -
9431-HASH.js gzip 5.62 kB N/A -
framework-HASH.js gzip 59.8 kB 59.8 kB
main-app-HASH.js gzip 256 B 253 B 🟢 3 B (-1%)
main-HASH.js gzip 39.7 kB 40.1 kB 🔴 +453 B (+1%)
webpack-HASH.js gzip 1.68 kB 1.68 kB
6105-HASH.js gzip N/A 5.63 kB -
764.HASH.js gzip N/A 169 B -
8898-HASH.js gzip N/A 63.4 kB -
9597-HASH.js gzip N/A 4.65 kB -
e1ccab69-HASH.js gzip N/A 62.9 kB -
Total 239 kB 239 kB ✅ -201 B
Polyfills
Canary PR Change
polyfills-HASH.js gzip 39.4 kB 39.4 kB
Total 39.4 kB 39.4 kB
Pages
Canary PR Change
_app-HASH.js gzip 194 B 194 B
_error-HASH.js gzip 183 B 182 B
css-HASH.js gzip 335 B 335 B
dynamic-HASH.js gzip 1.8 kB 1.8 kB
edge-ssr-HASH.js gzip 255 B 254 B
head-HASH.js gzip 351 B 349 B
hooks-HASH.js gzip 384 B 384 B
image-HASH.js gzip 580 B 580 B
index-HASH.js gzip 259 B 259 B
link-HASH.js gzip 2.49 kB 2.49 kB
routerDirect..HASH.js gzip 319 B 319 B
script-HASH.js gzip 386 B 386 B
withRouter-HASH.js gzip 315 B 313 B
1afbb74e6ecf..834.css gzip 106 B 106 B
Total 7.96 kB 7.95 kB ✅ -7 B

Server

Edge SSR
Canary PR Change
edge-ssr.js gzip 128 kB 128 kB
page.js gzip 283 kB 284 kB
Total 410 kB 412 kB ⚠️ +2.17 kB
Middleware
Canary PR Change
middleware-b..fest.js gzip 616 B 615 B
middleware-r..fest.js gzip 156 B 155 B
middleware.js gzip 45.3 kB 45.2 kB
edge-runtime..pack.js gzip 842 B 842 B
Total 46.9 kB 46.8 kB ✅ -46 B
Build Details
Build Manifests
Canary PR Change
_buildManifest.js gzip 719 B 720 B
Total 719 B 720 B ⚠️ +1 B
Build Cache
Canary PR Change
0.pack gzip 4.79 MB 4.78 MB 🟢 10.3 kB (0%)
index.pack gzip 117 kB 119 kB 🔴 +1.92 kB (+2%)
index.pack.old gzip 117 kB 120 kB 🔴 +3 kB (+3%)
Total 5.02 MB 5.02 MB ✅ -5.41 kB

🔄 Shared (bundler-independent)

Runtimes
Canary PR Change
app-page-exp...dev.js gzip 363 kB 363 kB
app-page-exp..prod.js gzip 201 kB 201 kB
app-page-tur...dev.js gzip 363 kB 363 kB
app-page-tur..prod.js gzip 201 kB 201 kB
app-page-tur...dev.js gzip 359 kB 359 kB
app-page-tur..prod.js gzip 199 kB 199 kB
app-page.run...dev.js gzip 360 kB 360 kB
app-page.run..prod.js gzip 199 kB 199 kB
app-route-ex...dev.js gzip 81.1 kB 81.1 kB
app-route-ex..prod.js gzip 55.2 kB 55.2 kB
app-route-tu...dev.js gzip 81.1 kB 81.1 kB
app-route-tu..prod.js gzip 55.2 kB 55.2 kB
app-route-tu...dev.js gzip 80.7 kB 80.7 kB
app-route-tu..prod.js gzip 55 kB 55 kB
app-route.ru...dev.js gzip 80.7 kB 80.7 kB
app-route.ru..prod.js gzip 54.9 kB 54.9 kB
dist_client_...dev.js gzip 324 B 324 B
dist_client_...dev.js gzip 326 B 326 B
dist_client_...dev.js gzip 318 B 318 B
dist_client_...dev.js gzip 317 B 317 B
pages-api-tu...dev.js gzip 45.2 kB 45.2 kB
pages-api-tu..prod.js gzip 34 kB 34 kB
pages-api.ru...dev.js gzip 45.2 kB 45.2 kB
pages-api.ru..prod.js gzip 33.9 kB 33.9 kB
pages-turbo....dev.js gzip 54.7 kB 54.7 kB
pages-turbo...prod.js gzip 39.6 kB 39.6 kB
pages.runtim...dev.js gzip 54.7 kB 54.7 kB
pages.runtim..prod.js gzip 39.6 kB 39.6 kB
server.runti..prod.js gzip 65.3 kB 65.3 kB
use-cache-pr...dev.js gzip 71.4 kB 71.4 kB
use-cache-pr...dev.js gzip 71.4 kB 71.4 kB
use-cache-pr...dev.js gzip 69.7 kB 69.7 kB
use-cache-pr...dev.js gzip 69.7 kB 69.7 kB
Total 3.48 MB 3.48 MB ✅ -3 B
📝 Changed Files (2 files)

Files with changes:

  • pages-api.ru..time.prod.js
  • pages.runtime.prod.js
View diffs
pages-api.ru..time.prod.js

Diff too large to display

pages.runtime.prod.js

Diff too large to display

📎 Tarball URL
https://vercel-packages.vercel.app/next/commits/946e81f4e17d523348e262bc6fa96da2f44c6f91/next

Commit: 946e81f

@lukesandberg
lukesandberg marked this pull request as ready for review July 10, 2026 19:46
@lukesandberg
lukesandberg enabled auto-merge (squash) July 13, 2026 05:37
Comment thread packages/next/src/build/type-check.ts
@lukesandberg
lukesandberg force-pushed the lukesandberg/ts-cli-followups branch from 43cfae9 to 946e81f Compare July 13, 2026 20:16
@lukesandberg
lukesandberg merged commit 63375cd into canary Jul 13, 2026
129 checks passed
@lukesandberg
lukesandberg deleted the lukesandberg/ts-cli-followups branch July 13, 2026 20:37
lukesandberg added a commit that referenced this pull request Jul 15, 2026
## Follow-ups for the experimental TypeScript CLI checker

Two independent improvements to the `experimental.useTypeScriptCli`
build path.

### 1. Make `tsc` responsive to interruption

When `next build` is interrupted (Ctrl-C / `SIGTERM`), the TypeScript 7
native compiler could keep running to completion instead of stopping —
leaving a CPU-heavy process alive after the build was abandoned.

The teardown already handled termination signals and killed the whole
process group; the problem was the signal it sent. The native compiler
ignores `SIGTERM`/`SIGINT`, so the graceful signal never stopped it. We
now escalate to `SIGKILL` (Windows: `taskkill /T /F`), which reaps the
compiler on interrupt (measured ~200ms vs. running to completion).

The compiler's signal handling may be improved upstream — see
[microsoft/typescript-go#4592](microsoft/typescript-go#4592),
which threads an interruption `context` through `tsc build`. That work
is still in progress; until it lands and ships, this escalation is what
makes interruption reliable.

### 2. Skip the jest worker for the CLI checker

The type-check runs in a jest worker to isolate the TypeScript
compiler-API heap so it can be freed after checking. In CLI mode the
compiler runs in a separate `tsc` process, so there is no heap to
isolate and the worker adds nothing but an extra process and
indirection. CLI mode now runs the setup/config path in-process and
spawns `tsc` directly. The TypeScript-API checker is unchanged and still
uses the worker.

### Testing

- Unit tests for `runTypeScriptCli` (spawn options, group-SIGKILL
teardown, signal handling, listener cleanup, captured-output decoding).
- Existing `test/production/app-dir/typescript-cli` integration suite
passes (TS 6, TS 7, opt-in-required, `ignoreBuildErrors`,
`--debug-build-paths`).
- Manually verified against a TypeScript 7 project large enough to
distinguish a real kill from natural completion: the native compiler is
reaped ~200ms after interrupt.

<!-- NEXT_JS_LLM_PR -->

(cherry picked from commit 63375cd)
lukesandberg added a commit that referenced this pull request Jul 23, 2026
## Follow-ups for the experimental TypeScript CLI checker

Two independent improvements to the `experimental.useTypeScriptCli`
build path.

### 1. Make `tsc` responsive to interruption

When `next build` is interrupted (Ctrl-C / `SIGTERM`), the TypeScript 7
native compiler could keep running to completion instead of stopping —
leaving a CPU-heavy process alive after the build was abandoned.

The teardown already handled termination signals and killed the whole
process group; the problem was the signal it sent. The native compiler
ignores `SIGTERM`/`SIGINT`, so the graceful signal never stopped it. We
now escalate to `SIGKILL` (Windows: `taskkill /T /F`), which reaps the
compiler on interrupt (measured ~200ms vs. running to completion).

The compiler's signal handling may be improved upstream — see
[microsoft/typescript-go#4592](microsoft/typescript-go#4592),
which threads an interruption `context` through `tsc build`. That work
is still in progress; until it lands and ships, this escalation is what
makes interruption reliable.

### 2. Skip the jest worker for the CLI checker

The type-check runs in a jest worker to isolate the TypeScript
compiler-API heap so it can be freed after checking. In CLI mode the
compiler runs in a separate `tsc` process, so there is no heap to
isolate and the worker adds nothing but an extra process and
indirection. CLI mode now runs the setup/config path in-process and
spawns `tsc` directly. The TypeScript-API checker is unchanged and still
uses the worker.

### Testing

- Unit tests for `runTypeScriptCli` (spawn options, group-SIGKILL
teardown, signal handling, listener cleanup, captured-output decoding).
- Existing `test/production/app-dir/typescript-cli` integration suite
passes (TS 6, TS 7, opt-in-required, `ignoreBuildErrors`,
`--debug-build-paths`).
- Manually verified against a TypeScript 7 project large enough to
distinguish a real kill from natural completion: the native compiler is
reaped ~200ms after interrupt.

<!-- NEXT_JS_LLM_PR -->

(cherry picked from commit 63375cd)
lukesandberg added a commit that referenced this pull request Jul 23, 2026
Backports the TypeScript 7 support fixes to the `16.2.x` release line to
resolve #95801, where `next build` crashes with a silent
`SIGSEGV`/`SIGABRT` when `typescript@7` is installed (the legacy
TypeScript JavaScript API is unavailable in TS7).

Cherry-picks the following, in order:

- #92277 — Resolve `compilerOptions.paths` in tsconfigs without
`compilerOptions.baseUrl` (prerequisite; source change only)
- #95639 — (TypeScript 7 Support) Add experimental TypeScript CLI
backend
- #95692 — Fix termination handling
- #95753 — Better support the CLI spinner when running the TSC CLI

Together these add the opt-in `experimental.useTypeScriptCli` backend
(runs the project-local `tsc` during `next build`, supporting TS7),
preserve the TypeScript API backend as the default with actionable TS7
migration guidance instead of a crash, and fix worker termination and
CLI spinner handling.

## Prerequisite: #92277

The TypeScript CLI backend tests exercise a `paths` alias that is
inherited from an extended tsconfig and defined **without** a `baseUrl`.
Resolving that alias in the **webpack** builder relies on the
`load-jsconfig.ts` change from #92277 (compute the effective base URL
from `pathsBasePath`), which had not been backported to `next-16-2`.
Only the source change from #92277 is included here — its test
reorganization is not.

## Test changes

The `test/production/ci-missing-typescript-deps` and
`test/production/next-server-nft` suites were converted from
`createNext` to `nextTestSetup` on `canary` in #93799, which was never
backported to `next-16-2`. Because #95639's test diffs were authored
against that refactored shape, the `ci-missing-typescript-deps` suite is
adapted back to this branch's existing `createNext` / `try‑finally`
style rather than pulling in the #93799 refactor.

## Fixes

Fixes #95801

## Verification

Automated (both bundlers):

- `pnpm --filter=next build`
- `pnpm test-start-turbo` and `pnpm test-start-webpack` for:
  - `test/production/app-dir/typescript-cli/typescript-cli.test.ts`
  - `test/production/ci-missing-typescript-deps/index.test.ts`
- Unit: `runTypeScriptCli.test.ts`,
`test/unit/typescript-cli-config-origin/index.test.ts`

Against a `typescript@7.0.2` reproduction project, `next build` no
longer crashes with an error about how `"id"` should be a string`. It
now exits cleanly with actionable guidance:

```
▲ Next.js 16.2.10 (Turbopack)

  Creating an optimized production build ...
✓ Compiled successfully in 785ms
  Running TypeScript  .TypeScript 7.0.2 does not provide the compiler API required by Next.js. Enable experimental.useTypeScriptCli in your Next.js config to use the TypeScript CLI, or install TypeScript 6 instead.
Next.js build worker exited with code: 1 and signal: null
```

The same clean error is produced under `CI=1` (previously the crash
path). Enabling the new opt-in:

```ts
experimental: {
  useTypeScriptCli: true,
},
```

makes the build succeed with TypeScript 7 installed.

---------

Co-authored-by: Tim Neutkens <tim@timneutkens.nl>
m-kawafuji pushed a commit to m-kawafuji/next.js that referenced this pull request Aug 8, 2026
## Follow-ups for the experimental TypeScript CLI checker

Two independent improvements to the `experimental.useTypeScriptCli`
build path.

### 1. Make `tsc` responsive to interruption

When `next build` is interrupted (Ctrl-C / `SIGTERM`), the TypeScript 7
native compiler could keep running to completion instead of stopping —
leaving a CPU-heavy process alive after the build was abandoned.

The teardown already handled termination signals and killed the whole
process group; the problem was the signal it sent. The native compiler
ignores `SIGTERM`/`SIGINT`, so the graceful signal never stopped it. We
now escalate to `SIGKILL` (Windows: `taskkill /T /F`), which reaps the
compiler on interrupt (measured ~200ms vs. running to completion).

The compiler's signal handling may be improved upstream — see
[microsoft/typescript-go#4592](microsoft/typescript-go#4592),
which threads an interruption `context` through `tsc build`. That work
is still in progress; until it lands and ships, this escalation is what
makes interruption reliable.

### 2. Skip the jest worker for the CLI checker

The type-check runs in a jest worker to isolate the TypeScript
compiler-API heap so it can be freed after checking. In CLI mode the
compiler runs in a separate `tsc` process, so there is no heap to
isolate and the worker adds nothing but an extra process and
indirection. CLI mode now runs the setup/config path in-process and
spawns `tsc` directly. The TypeScript-API checker is unchanged and still
uses the worker.

### Testing

- Unit tests for `runTypeScriptCli` (spawn options, group-SIGKILL
teardown, signal handling, listener cleanup, captured-output decoding).
- Existing `test/production/app-dir/typescript-cli` integration suite
passes (TS 6, TS 7, opt-in-required, `ignoreBuildErrors`,
`--debug-build-paths`).
- Manually verified against a TypeScript 7 project large enough to
distinguish a real kill from natural completion: the native compiler is
reaped ~200ms after interrupt.

<!-- NEXT_JS_LLM_PR -->
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.

2 participants