2

I'm importing forkJoin as

import 'rxjs/add/observable/forkJoin';

but I'm still getting an error in my console:

__WEBPACK_IMPORTED_MODULE_2_rxjs_Observable__.a.forkJoin is not a function

I don't get this error in the Angular CLI compiler (using ng serve) nor does VS Code complain. Is there a different method of running forkJoin now? I'm running the latest build of Angular (5.*), with RxJS 5.5.*.

As requested, it's being called as thus:

Observable.forkJoin(
    this.eventService.getTypes().first(),
    this.eventService.getDates().first()
).pipe(
Rohit
  • 3,018
  • 2
  • 29
  • 58
  • what version of rxjs you are using? – Suren Srapyan Jan 17 '18 at 05:36
  • @SurenSrapyan Sorry, you're right, that's more relevant. My package.json is set to ^5.5.2, though not positive of the actual subversion. – Rohit Jan 17 '18 at 05:37
  • Sorry, that was a case of typo in typing the code in. In hindsight, don't know why I typed it instead of copying it. – Rohit Jan 17 '18 at 05:39
  • 1
    are you saying you don't get this error with @angular/cli, but using webpack, you do? – Michael Kang Jan 17 '18 at 05:44
  • The error does not appear in the Angular CLI output, but does show up in the Chrome dev tools. I'm not doing any independent builds; it's all through ngCLI. – Rohit Jan 17 '18 at 06:01
  • Can you show us how you call the forkJoin please ? – Noémi Salaün Jan 17 '18 at 07:44
  • See this, [Error rxjs_Observable__.Observable.forkJoin is not a function](https://stackoverflow.com/questions/44743823/error-rxjs-observable-observable-forkjoin-is-not-a-function). Silly question are you first importing `import { Observable } from 'rxjs/Observable'`? – Richard Matsen Jan 17 '18 at 08:07
  • @NoémiSalaün @RichardMatsen Yup, importing `Observable`, and sure, I'll throw in how it's being called. – Rohit Jan 17 '18 at 12:34

1 Answers1

6

With RxJS 5.5 you should use it as a function. I'm not sure if Angular CLI 1.5 and newer are even configured to use the older prototype patching style of RxJS.

import { forkJoin } from 'rxjs/observable/forkJoin'

...

forkJoin(...).pipe(...).subscribe(...);
martin
  • 93,354
  • 25
  • 191
  • 226
  • I'll give that a shot. It still feels weird using some of the methods as functions of their own, like `range`. It's so generic, having the Observable namespace feels more appropriate. – Rohit Jan 17 '18 at 12:35
  • 1
    That's just the recommended way of using RxJS since 5.5. – martin Jan 17 '18 at 12:37