Rxjs: Some environments fail with global.global === global in util/root.ts incorrectly

Created on 13 Feb 2017  路  24Comments  路  Source: ReactiveX/rxjs

RxJS version:
5.1.1

Code to reproduce:
Load the library in an Appcelerator Titanium app environment.

Expected behavior:
App to load and RxJS to work.

Actual behavior:
App fails to load and throws the error "RxJS could not find any global context (window, self, global)"

Additional information:
The global variable is available but the check global.global === global fails because global does not contain a reference to itself. See https://github.com/ReactiveX/rxjs/blob/master/src/util/root.ts#L18.

Agenda Item

All 24 comments

This seems similar to other issues like https://github.com/ReactiveX/rxjs/issues/2168 , global context is mutated by its environment. Can you possibly confirm environment you tried mutate its global context?

I checked and global.global is null in the environment causing the check (global.global === global) to fail.

@thomasconner yes, that's I figured in original issue. Question is if your environment (Titanium) is mutating global context. Our context check is designed to work with node.js, and browser environment natively, but some framework mutates its global context for several purpose like test framework for environment isolation, etcs. I'd like to confirm if this issue is those cases.

@kwonoj I am not sure if Titanium mutates the global context. I have searched their documents with no success.

Why is it necessary to check global.global === global?

@thomasconner mostly as a convention to confirm it really is the global we want, instead of just a variable that happens to be named global 馃槺 which would be really hard to debug if we start using some random variable.

That said, I believe TC39 has looked into how often people in practice use global in the global scope _that doesn't refer to the real global_ e.g. window and found it not to be an issue. They're trying to standardize around global spec: https://github.com/tc39/proposal-global

I'm OK with removing the global.global window.window checks, but others may have concerns.

@jayphelps Thanks for the explanation. Right now I am stuck and have to fallback to 5.0.0-beta.12 to get RxJS to work. I would vote to remove it the global.global and window.window checks. I don't mind making a PR if you would like me too.

@thomasconner you shouldn't be stuck? Seems pretty easy to work around.

// assign global to global somewhere that happens _before_ your first rxjs import.
// i.e. in whatever the entry file for appcelerator is
global.global = global;
// later
var rx = require('rxjs');

I would vote to remove it the global.global and window.window checks. I don't mind making a PR if you would like me too.

We need to be sure we're not fixing something for one person but causing issues for others.

Possibly this could work but my use case is a little different then just writing an application. I am one of the maintainers for a JavaScript SDK that uses RxJS and is bundled for several environments (Angular, BackboneJs, NodeJS, Cordova/PhoneGap, and TitaniumJS).

I don't think we should require developers who use our SDK to add global.global = global to the top of their entry file for the application. I could possibly add this for the titanium bundle but I have not given that a try at the moment.

I just wanted to further understand the reason for the checks and if it was necessary before I pursued other options.

@thomasconner We'll look into possibly relaxing the check as well as possibly asking Appcelerator to define global.global because it claims to have node.js interop and it's fairly standard for the global variable (window, self, global) to assign to itself as a way to confirm it's really the global

@jayphelps Thanks. I will try to add global.global to the Titanium bundle for now.

Filed a ticket with Appcelerator: jira.atlassian.com/secure/WikiRendererHelpAction.jspa?section=links https://jira.appcelerator.org/browse/TIMOB-24404

@jayphelps I don't think the link for the ticket is correct.

@thomasconner indeed. sorry bout that https://jira.appcelerator.org/browse/TIMOB-24404

Hans from Appcelerator here, thanks for filing the issue @jayphelps! 馃槉 We're looking into it.

I was able to solve the issue for now by including this code in my bundle

// Temporary fix for RxJS https://github.com/ReactiveX/rxjs/issues/2366
global.global = global;

Hi !

I'm facing the same issue since the release of 5.3.2, it's an Angular 2 project, TSLint and webpack compiler are not happy with these tests ...

I tried to workaround with global.global = global; but I don't know where is the good place to inject this cause I don't think TSLint is actually reading files in a predefined order ...

You can see my pull request here and my failed build here
Thanks in advance

Fixed with the release of 5.4.0 :smile:
https://github.com/SherlockStd/ME4N-Starter/pull/3

@thomasconner I can confirm that 5.4.0 changed the way we look up the global root, no longer doing global.global = global checks, so this should now be resolved. Let us know if not! 馃帀

@jayphelps Ok thanks. I will.

Note that @SherlockStd's problem with 5.3.2 is actually not related to this issue ticket. 5.3.2 was a bad release, broken for everyone https://github.com/ReactiveX/rxjs/issues/2598 fixed in 5.3.3 (as well as the latest 5.4.0)

@jayphelps I finally got around to updating rxjs to the latest release. Everything worked great with no work arounds. This issue is resolved with the latest release

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings