Diagnose an unusable TypeScript install instead of failing at compile time
fix: diagnose an unusable TypeScript install instead of failing at compile time
Diagnose an unusable TypeScript install instead of failing at compile time54b54b-fix-diagnose-an-unusable-typescript-install-instead-cve-2026-92935fixdiagnose unusable typescript install instead failing
Committed by patriksimek-bot
commit message
fix: diagnose an unusable TypeScript install instead of failing at compile time
TypeScript 7 (the Go rewrite) reduced the package entry point to
{ version, versionMajorMinor }. transpileModule() and ModuleKind, both used by
getTypeScriptCompiler, are gone from it; the replacement API is published under
the explicitly unstable typescript/unstable/* subpaths and offers no
single-file transpile equivalent, so there is nothing to fall back to.
The real defect was where the failure surfaced. require('typescript') still
SUCCEEDS on 7.x, so the existing catch -- which reports "TypeScript compiler is
not installed." -- never fired. The API was only touched inside the returned
callback, so users got
TypeError: Cannot read properties of undefined (reading 'CommonJS')
thrown from VMScript.getCompiledCode, which reads like a vm2 bug rather than a
version mismatch, and points at neither the cause nor the fix.
Both compiler loaders now validate their module's API at lookup time, so an
unusable install fails at `new VMScript(...)` with a message naming the
installed version, a version that works, and the custom-compiler escape hatch.
coffee-script gets the same treatment; it had the identical latent shape.
This does not add TypeScript 7 support -- it makes the failure legible.
Supporting 7.x would mean building a Program over a virtual filesystem against
an API upstream labels unstable, which is a design decision, not a bugfix.
Both require() calls stay literal: bundlers resolve them statically, and the
existing webpack-warning comments depend on that, which rules out extracting a
shared loader helper.
Tests: three cases driving a 7.x-shaped stub through require.cache, so they run
without TypeScript 7 present. The existing 'run TypeScript' case is now gated on
a capability probe rather than a version number, so test:compilers is honest on
either major -- 5 passing on typescript@6, 4 passing + 1 pending on 7.0.2.
README: adds a Compilers section (there was none -- compiler support was
documented only as a one-line option bullet in two places), notes the
constraint on both `compiler` bullets, and adds a Known Issues entry. The
documented error text is verified against the message the code actually throws.
The section also states, for the first time, that a custom compiler runs in the
host realm before sandboxing -- worth being explicit about now that the docs
actively recommend supplying one.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>Editor assessment
This commit patches CVE-2026-92935. Strong body. It explains the TypeScript 7 entry-point reduction, why require('typescript') still succeeds so the old catch never fired, the misleading downstream TypeError, and the fix: validate the module API at lookup time and report the installed version, a working version and the custom-compiler escape hatch. It also notes that supporting 7.x is deliberately out of scope. Clear and useful. Formally the message is clean - no scope, no trailing period, well-separated body - and the explanation is self-sufficient.