API: `tsc.exe` opens a visible console window on Windows when the parent process has no console

Aperta Adatta ai principianti
#65,083 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
75/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
node.js, typescript
Ambito
api, devtools

Direzione di ricerca

Inizia dalle chiamate che avviano processi in dist/api/syncChannel.js e dist/api/async/client.js, poi controlla i file sorgente e i test corrispondenti. Riproduci la segnalazione su Windows usando il launcher fornito e verifica entrambi i percorsi API. L’obiettivo è che tsc.exe si avvii senza una finestra della console visibile quando il processo padre non ha una console.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

🔎 Search Terms

windowsHide, tsc.exe console window, API console window Windows spawn, SyncRpcChannel, ELECTRON_RUN_AS_NODE, cmd window opens, console window flash Windows, conhost tsc

🕗 Version & Regression Information
  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about Windows console windows and the API

I reproduced this on 7.0.2, 7.1.0-beta, and 7.1.0-dev.20261031.1. TypeScript 6.0.3 does not export this API.

⏯ Playground Link

No response

💻 Code

Install typescript@next in an empty directory on Windows and add these two files.

api-console.mjs (on 7.0.2, import from typescript/unstable/sync):

import { API } from "typescript/sync";

const api = new API({ cwd: process.cwd() });
setTimeout(() => api.close(), 8_000);

launch.mjs (replace the path with your VS Code installation):

import { spawn } from "node:child_process";

const env = { ...process.env, ELECTRON_RUN_AS_NODE: "1" };
spawn("C:/path/to/Microsoft VS Code/Code.exe", ["api-console.mjs"], {
  detached: true,
  stdio: "ignore",
  env,
}).unref();

Run node launch.mjs.

detached: true starts Code.exe without a console. Running api-console.mjs directly with Node from a terminal does not show the problem.

🙁 Actual behavior

A console window opens and stays open until the API closes. Its title is the path of tsc.exe. In my environment, Windows Terminal is the default terminal application, so the window opens in Windows Terminal.

This is wrong because the API communicates through pipes, so users have no reason to see this window. Tools that start one API for each project or restart the API open several windows. I found this in a VS Code extension.

🙂 Expected behavior

tsc.exe runs without a visible window, regardless of whether the parent process has a console.

Additional information about the issue

Code.exe is a GUI subsystem program, so it has no console even when it runs with ELECTRON_RUN_AS_NODE=1. Windows therefore creates a new console for tsc.exe. Other Electron-based hosts should behave the same way, but I tested only Code.exe.

These calls do not pass windowsHide in the published 7.1.0-dev.20261031.1 package:

  • dist/api/syncChannel.js: the call that starts tsc.exe with --pipe
  • dist/api/async/client.js: the call that starts tsc.exe with stdio pipes

Passing windowsHide: true in these calls should fix the problem. I confirmed this on 7.0.2 with the sync API: the unchanged script opened one window, and a run with windowsHide: true added to spawn opened none. tsc.exe started in both runs. I did not run the async API.

As a workaround, we temporarily replace child_process.spawn, call syncBuiltinESMExports(), and construct API. This works only because the sync API spawns in its constructor, and it depends on internal behavior.


AI Disclosure: Used Claude Opus 5.5 for investigation and writing.

Lingua principale
Go
Stelle
112k
Fork
16k
Merge medio
3g 4h
PR unite (30g)
145

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di microsoft/TypeScript

Tutte le issue di microsoft/TypeScript

Issue simili

Altre issue su Go

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.