question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

angular2-jwt ERROR TypeError: Observable_1.Observable.defer is not a function at AuthHttp.request (angular2-jwt.js:140)

See original GitHub issue

I am looking to reuse a service developed for an Ionic project in another project. Both applications are based on the same versions of libraries.

The service (Provider) has the following code: import {Injectable} from ‘@angular/core’; import {AuthHttp} from ‘angular2-jwt’;

import { Headers, RequestOptions } from ‘@angular/http’;

import ‘rxjs/add/operator/map’; import ‘rxjs/add/operator/toPromise’;

import * as AppConfig from ‘…/app/config’;

import {Storage} from ‘@ionic/storage’;

@Injectable() export class BusinessService {

private cfg: any;

constructor( private authHttp: AuthHttp, public storage: Storage

`)` 
`{`

	`this.cfg` = AppConfig.cfg;

`}`

listItems() {

`return this.authHttp.get(this.cfg.apiUrl + this.cfg.businessServices.listItems()) .toPromise() .then(rs => { console.log(rs, rs.json()); return rs.json(); }); }

I call the method in the home page like this: import {BusinessService} from ‘…/…/services/business-service’; … this.BusinessService.listItems() .then(data => {

			...
		})
		.catch(e => console.log(" error", e));

I always get the following error:

core.es5.js:1020 ERROR TypeError: Observable_1.Observable.defer is not a function at AuthHttp.request (angular2-jwt.js:140) at AuthHttp.requestHelper (angular2-jwt.js:104) at AuthHttp.get (angular2-jwt.js:151) at BusinessService.webpackJsonp.355.BusinessService.listItems (main.js:398) at HomePage.webpackJsonp.354.HomePage.listItems(orders.ts:20)

In the app.module file, I made the following settings: import {HttpClientModule, HttpClient} from ‘@angular/common/http’; import {HttpModule, Http} from ‘@angular/http’; import {AuthHttp, AuthConfig,JwtHelper} from ‘angular2-jwt’;

… imports: [ BrowserModule, HttpClientModule, HttpModule, … providers: [ StatusBar, SplashScreen, JwtHelper, { provide: AuthHttp, useFactory: getAuthHttp, deps: [Http] }, BusinessService

Here is the result of my ionic info: ionic (Ionic CLI) : 4.0.5 (C:\Users\kamahunda\AppData\Roaming\npm\node_modules\ionic) Ionic Framework : ionic-angular 3.8.0 @ionic/app-scripts : 3.0.1

Cordova:

cordova (Cordova CLI) : 8.0.0 Cordova Platforms : android 7.0.0

System:

NodeJS : v8.9.3 (C:\Program Files\nodejs\node.exe) npm : 6.4.1 OS : Windows 10

Environment:

ANDROID_HOME : not set

Here are the library versions in my package.json “angular2-jwt”: “^0.2.3”, “rxjs”: “^6.2.0”, “rxjs-compat”: “^6.2.0”, “@angular/common”: “4.4.4”, “@angular/compiler”: “4.4.4”, “@angular/compiler-cli”: “4.4.4”, “@angular/core”: “4.4.4”, “@angular/forms”: “4.4.4”, “@angular/http”: “4.4.4”, “@angular/platform-browser”: “4.4.4”,

Any help would be welcome.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:3
  • Comments:5

github_iconTop GitHub Comments

2reactions
LuisZidannycommented, Mar 7, 2019

você terá que ir no arquivo angular2-jwt.js ! no começo do código alterar e deixando essa duas linha aqui

var Observable_1 = require(“rxjs”); require(“rxjs/operator”);

No codigo da linha 138 ate 146 um retorno lá você vai ver apaque o Observable e deixe assim Observable_1.defer só isso para essa versão

return Observable_1.defer(function () { var token = _this.config.tokenGetter(); if (token instanceof Promise) { return Observable_1.Observable.fromPromise(token).mergeMap(function (jwtToken) { return _this.requestWithToken(req, jwtToken); }); } else { return _this.requestWithToken(req, token); } });

0reactions
stale[bot]commented, Oct 26, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you have not received a response for our team (apologies for the delay) and this is still a blocker, please reply with additional information or just a ping. Thank you for your contribution! 🙇‍♂️

Read more comments on GitHub >

github_iconTop Results From Across the Web

ERROR:Observable_1.Observable.defer is not a function ...
TypeError : Observable_1.Observable.defer is not a function at AuthHttp.push../node_modules/angular2-jwt/angular2-jwt.js.AuthHttp.request ...
Read more >
@auth0/angular-jwt - npm
This library provides an HttpInterceptor which automatically attaches a JSON Web Token to HttpClient requests. This library does not have ...
Read more >
angular2-jwt | Yarn - Package Manager
angular2-jwt is a helper library for working with JWTs in your Angular 2 applications. For examples of integrating angular2-jwt with SystemJS, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found