Skip to content

Avoid TypeScript 7 startup crash by loading transpilation lazily - #4724

Open
KiritoYG wants to merge 1 commit into
tscircuit:mainfrom
KiritoYG:codex/fix-typescript7-startup
Open

Avoid TypeScript 7 startup crash by loading transpilation lazily#4724
KiritoYG wants to merge 1 commit into
tscircuit:mainfrom
KiritoYG:codex/fix-typescript7-startup

Conversation

@KiritoYG

Copy link
Copy Markdown

Addresses #4706.

With TypeScript 7 installed, eagerly importing the Rollup TypeScript plugin throws at ModuleKind.ES2015 before any CLI command can run. Defer the compiler and Rollup imports until transpilation is requested, and check for the traditional JavaScript compiler API before initializing the plugins. Circuit builds that do not enable transpilation, --help, and --version can run; transpile and build --transpile exit with an actionable compatibility message that recommends TypeScript 5.9.3.

Add a subprocess regression that reproduces TypeScript 7's version-only main export without changing the compiler used by other tests. It checks successful non-transpiling builds and board/component output, successful help/version commands, and nonzero exits with the compatibility diagnostic for both explicit transpilation commands and build.typescriptLibrary: true configuration.

Validation on Windows x64, Bun 1.4.2:

  • New compatibility regression: 1 test, 22 assertions passed. Before the change its initial version failed at the original ModuleKind.ES2015 startup error.
  • Existing tests/cli/transpile/transpile.test.ts and tests/cli/build/build-transpile.test.ts: 11 tests, 55 assertions passed, including ESM, CommonJS, declarations and explicit .ts/.tsx extension handling.
  • bun run build, bun x --no-install tsc --noEmit, formatting of both changed files, dependency policy check, and git diff --check passed.
  • Separately tested the generated dist/cli/main.js with the actual npm TypeScript 7.0.2 package, not a mock. Eager plugin import reproduced the original error. Help, version and a one-resistor circuit build exited 0; the circuit output contained a board and R1. Both transpilation commands exited 1 with the compatibility/install message. Restored TypeScript 5.9.3 afterward.

This protects startup and non-transpiling circuit builds; it does not port transpilation or other compiler-API-dependent features to TypeScript 7. In particular, tsci dev still has dependency-analysis code that uses the old compiler API and remains outside this fix. build --ci enables transpilation on its normal build path (a custom buildCommand can handle the command earlier), and build.typescriptLibrary: true enables it through configuration; these paths still require a compatible compiler. Full end-to-end dev and --ci runs were not performed. No new dependencies or lockfile changes.

Validation caveat: one existing Windows test embeds an unescaped absolute path into generated TSX and does not assert its child exit code. Its test assertions passed although that child circuit build reported an import error. The new compatibility regression asserts exit codes explicitly. The entire repository suite and Linux CI have not been run locally.

AI assistance: implementation and verification were coordinated with Codex, with an independent source review by Claude. The review's suggestions were checked against the repository and verified behavior before finalizing this patch.

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