Description
Acknowledgement
- I acknowledge that issues using this template may be closed without further explanation at the maintainer's discretion.
Comment
This came up after sending the initial Google v5.5-beta feedback in #58685 since I was just looking at build failures for that feedback.
Apologies if this isn't an officially supported way of using the TypeScript compiler or not - most of the docs I can find are specific to running the compiler via Node.
Google has some internal web apps that load the bundled TSC from https://github.com/microsoft/TypeScript/blob/v5.5-rc/lib/typescript.js file in a browser. One example use case is a tool similar to https://www.typescriptlang.org/play/.
In TS 5.5 these apps break at runtime because they call methods on the global ts
object like ts.createLanguageService
, but ts
is now just an empty object with no properties. I narrowed this down to the bundling changes in #57133. Here's typescript.js before & after:
var ts = (() => {
// lots and lots of code
return require_typescript();
})();
if (typeof module !== "undefined" && module.exports) { module.exports = ts; }
var ts = {}; ((module) => {
// lots and lots of code
module.exports = __toCommonJS(typescript_exports);
// even more code
})(typeof module !== "undefined" && module.exports ? module : { exports: ts });
if (typeof module !== "undefined" && module.exports) { ts = module.exports; }
I'd assume that in v5.5-rc, ts
was intended to be instantiated via passing {exports : ts }
as the module
argument to this IIFE, causing the exported functions that are put on module.exports
to also be defined as properties on ts
. Instead the module.exports = __toCommonJS(typescript_exports);
assignment just overwrites ts
in {exports: ts}
and ts
is just an empty object.