X Tutup
Skip to content

TypeError: Cannot read property 'Subject' of undefined with System.js 0.18.10 #3643

@mgechev

Description

@mgechev

While updating the system.js version of the angular2-seed I encountered issue with the following stack trace:

EXCEPTION: Error during instantiation of function (_platformStrategy, href) {! (function (_router, _location) { -> Router -> function (_platformStrategy, href) {).
angular2.js?v=0.0.0:7244 ORIGINAL EXCEPTION: TypeError: Cannot read property 'Subject' of undefined
angular2.js?v=0.0.0:7244 ORIGINAL STACKTRACE:
angular2.js?v=0.0.0:7244 TypeError: Cannot read property 'Subject' of undefined
    at new EventEmitter (angular2.js?v=0.0.0:8605)
    at new <anonymous> (router.js?v=0.0.0:5998)
    at execute.ReflectionCapabilities.factory (angular2.js?v=0.0.0:22737)
    at Injector.execute.Injector._new (angular2.js?v=0.0.0:12674)
    at InjectorDynamicStrategy.execute.InjectorDynamicStrategy.getObjByKeyId (angular2.js?v=0.0.0:12534)
    at Injector.execute.Injector._getByKeyUnbounded (angular2.js?v=0.0.0:12799)
    at Injector.execute.Injector._getByKey (angular2.js?v=0.0.0:12753)
    at Injector.execute.Injector._getByDependency (angular2.js?v=0.0.0:12741)
    at Injector.execute.Injector._new (angular2.js?v=0.0.0:12640)
    at InjectorDynamicStrategy.execute.InjectorDynamicStrategy.getObjByKeyId (angular2.js?v=0.0.0:12534)
angular2.js?v=0.0.0:7244 ERROR CONTEXT:
angular2.js?v=0.0.0:7244 _Context {element: a.ng-binding, componentElement: app, injector: Injector}

Debugging it further I reached this line. With the newest version of System.js the default property does not have Rx field.

Here's a workaround, which may work:

if (Rx.hasOwnProperty('default')) {
  let rxDefault = (<any>Rx).default;
  if (rxDefault.Rx) {
    this._subject = new rxDefault.Rx.Subject();
  } else {
    this._subject = new rxDefault.Subject();
  }
  this._immediateScheduler = (<any>Rx).default.Rx.Scheduler.immediate;
} else {
  this._subject = new Rx.Subject<any>();
  this._immediateScheduler = (<any>Rx.Scheduler).immediate;
}

However, I'm not sure it is the best solution. Let me know if you think it is good enough in order to initiate a pull request.

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

      X Tutup