NativeScript Angular fails on RxJS Observable after 5.2 upgrade


App works file with Angular@4.4.6 and nativescript-angular@4.4.1.

After upgrading all to 5.2.0, I’m getting the following error when the app starts on iOS:

In ‘document.createElement(‘script’)’, ‘document.createElement’ is undefined

Looks like code is trying to initialize RxJS Observable class and falls into document.createElement, which obviously does not exist in NativeScript.

That code is inside a package I’m importing in my code (js44d), which uses RxJS Observable and HttpClient calls.

Any idea how to fix it?

FYI: same code, and library, works fine on web, of course.


Here is the full error stack:

***** Fatal JavaScript exception - application has been terminated. *****
Native stack trace:
1 0x10f11e724 -[TNSRuntime executeModule:referredBy:]
2 0x10ebbc691 main
3 0x114c71d81 start
4 0x1
JavaScript stack trace:
1 canUseReadyStateChange@file:///app/tns_modules/js44d/bundles/js44d.umd.js:22427:82
2 ImmediateDefinition@file:///app/tns_modules/js44d/bundles/js44d.umd.js:22401:49
3 @file:///app/tns_modules/js44d/bundles/js44d.umd.js:22579:42
4 @file:///app/tns_modules/js44d/bundles/js44d.umd.js:2:72
5 anonymous@file:///app/tns_modules/js44d/bundles/js44d.umd.js:5:2
6 evaluate@[native code]
7 moduleEvaluation@[native code]
8 @[native code]
9 promiseReactionJob@[native code]
10 require@[native code]
11 anonymous@file:///app/app/fourDAdmin.web.module.js:19:22
12 evaluate@[native code]
13 moduleEvaluation@[native code]
14 @[native code]
15 promiseReactionJob@[native code]
16 require@[native code]
17 anonymous@file:///app/main.js:4:38
18 evaluate@[native code]
19 moduleEvaluation@[native code]
20 @[native code]
21 promiseReactionJob@[native code]
JavaScript error:
file:///app/tns_modules/js44d/bundles/js44d.umd.js:22427:82: JS ERROR TypeError: document.createElement is not a function. (In ‘document.createElement(‘script’)’, ‘document.createElement’ is undefined)


I did a quick experiment with a new sample app generated by Sidekick. It works fine with 5.2, of course.

But if I do:

npm install js44d --save
npm install @types/kendo-ui --save-dev

And try to run it again I get the same error.

ps: that kendo-ui types is just to avoid compile errors, because that js44d library needs that for the web side. That package should work for web & mobile.


I was facing the same error and realised that I need to import Subscription from rxJs/Subscription so I have modified
import { Subscription } from ‘rxJs’ —>
import { Subscription } from ‘rxJs/Subscription’

and Observable from ‘rxjs/Observable’ that has solved my problem. I am using “rxjs”: “~5.5.2”


not my case. the only reference I have to Observable is via rxJs/Observable, and it does not matter the ‘rxJs’ version. I’ve tried different versions and the result is always the same.

It is related to nativescript-angular version. Anything above 5.0.0 produces the error above.


Found the problem.

That js44d package was poorly built and included the entire ‘rxjs’ bundle and that caused the reported runtime error. Once js44d got fixed that error is gone.

Sorry to bother you guys here.