0

I'm trying to move an Angular 5 project, created using webpack but without using Angular CLI, into an Angular CLI project. The following code used to work just fine:

return this.httpClient.jsonp<Foo>('http://some.url', 'callback').timeout(timeout).toPromise();

This still compiles without error, but at runtime I'm now failing with "timeout is not a function".

So I could get a better look in a debugger at what was going on, I changed the above to:

const observable = this.httpClient.jsonp<Foo>('http://some.url', 'callback');

When I run this in my old project, the observable I get back looks very different from what I get back in the new Angular CLI project -- the Observable has a timeout function, and many other functions, that are completely missing from the Observable returned by the new project.

In both cases it's the same version of Angular, the same HttpClient imported from '@angular/common/http', but somehow in the new project I get some sort of bare bones, stripped-down version of an Observable that's missing the functionality I need, and that the compiler expects should be there.

My two main guesses as to what's going wrong are that I'm missing a polyfill that adds a lot of functionality to Observable, or that somehow within the module loading process the wrong kind of Observable is replacing the Observable that I used to get.

I've compared polyfills.ts from both projects, however, compared package versions in both package.json files, particularly of rxjs, but nothing leaps out at me, nothing I've tried tinkering with makes a difference.

kshetline
  • 12,547
  • 4
  • 37
  • 73
  • Did you import `timeout` from rxjs? Did you import `Observable`? https://stackoverflow.com/questions/38990350/angular-2-rxjs-timeout-callback#38991912 Likely that in your old project you had a dependency that imported these and were available w/o you even realizing – Z. Bagley Feb 06 '18 at 12:44
  • 1
    I had no idea that I had to import timeout explicitly. Now that I do that, the timeout works perfectly. Thanks! – kshetline Feb 06 '18 at 13:04

0 Answers0