Skip to content
This repository was archived by the owner on May 22, 2025. It is now read-only.
This repository was archived by the owner on May 22, 2025. It is now read-only.

tsickle fails on RxJS due to "body of a goog.module cannot use throw" #420

Open
@kylecordes

Description

@kylecordes

With a lot of tweaking of the right config in the right place, this repo branch gets most of the way to tsickling RxJS:

https://github.com/kylecordes/tsickle-fiddling/tree/build-rxjs

I wish the steps to get here were smaller, of course, but it's quite easy to run, or just read on:

rxjs/util/root.js:11: ERROR - The body of a goog.module cannot use throw.
    throw new Error('RxJS could not find any global context (window, self, global)');
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

That file, emitted by tsickle:

goog.module('rxjs.util.root'); exports = {}; var module = {id: 'rxjs/util/root.js'};
/**
 * window: browser in DOM main thread
 * self: browser in WebWorker
 * global: Node.js/other
 */
exports.root = (typeof window == 'object' && window.window === window && window
    || typeof self == 'object' && self.self === self && self
    || typeof global == 'object' && global.global === global && global);
if (!exports.root) {
    throw new Error('RxJS could not find any global context (window, self, global)');
}
//# sourceMappingURL=root.js.map

I'm not sure where to go from here, but if I make the assumption "the goal of tsickle is to take most valid TypeScript code and make it valid properly typed Closure code", then the above seems like a bug or missing feature in tsickle. With that fig leaf as an excuse to enter this as an issue... here's what I'm trying to figure out:

  • Any pointer in the right direction to work toward tsickling RxJS?
  • Might I need to rearrange RxJS to somehow avoid problematic throw?
  • Manually convert a module or two to get past this limitation?
  • Beg the Closure team to support throw inside goog.modules?
  • Make tsickle emit ES2015 modules with type comments, which Closure can (?) recently consume, perhaps without this throw limitation?
  • Decide instead that some libraries are too painful to tsickle, and consume them in Closure as ES2015 and without full typing?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions