【问题标题】:Typescript Error : Module '".../node_modules/rxjs/Rx"' has no exported member 'SubscriptionLike' [duplicate]打字稿错误:模块'“.../node_modules/rxjs/Rx”'没有导出的成员'SubscriptionLike' [重复]
【发布时间】:2018-11-13 15:34:54
【问题描述】:

基本上,我正在尝试构建一个向服务器发送 http 请求并在应用程序上显示数据的应用程序。我正在关注这个tutorial。我在那里显示了这些步骤。但是在安装了所有模块后,我得到了以下异常.我对离子知之甚少。所以给我一篇文章和描述性的解决方案。

packages.json

 {
  "name": "CompassApp",
  "version": "0.0.1",
  "author": "Ionic Framework",
  "homepage": "http://ionicframework.com/",
  "private": true,
  "scripts": {
    "clean": "ionic-app-scripts clean",
    "build": "ionic-app-scripts build",
    "lint": "ionic-app-scripts lint",
    "ionic:build": "ionic-app-scripts build",
    "ionic:serve": "ionic-app-scripts serve"
  },
  "dependencies": {
    "@agm/core": "^1.0.0-beta.3",
    "@angular/animations": "5.2.10",
    "@angular/common": "^6.0.3",
    "@angular/compiler": "^6.0.3",
    "@angular/compiler-cli": "^6.0.3",
    "@angular/core": "^6.0.3",
    "@angular/forms": "^6.0.3",
    "@angular/http": "^6.0.3",
    "@angular/platform-browser": "^6.0.3",
    "@angular/platform-browser-dynamic": "^6.0.3",
    "@ionic-native/barcode-scanner": "^4.7.0",
    "@ionic-native/core": "4.7.0",
    "@ionic-native/http": "^4.7.0",
    "@ionic-native/splash-screen": "4.7.0",
    "@ionic-native/status-bar": "4.7.0",
    "@ionic/pro": "1.0.20",
    "@ionic/storage": "2.1.3",
    "angularfire2": "^5.0.0-rc.10",
    "cordova-plugin-advanced-http": "^1.11.1",
    "firebase": "^5.0.4",
    "ionic-angular": "3.9.2",
    "ionicons": "3.0.0",
    "phonegap-plugin-barcodescanner": "^8.0.0",
    "rxjs": "^5.5.11",
    "sw-toolbox": "3.6.0",
    "zone.js": "0.8.26"
  },
  "devDependencies": {
    "@ionic/app-scripts": "3.1.9",
    "typescript": "~2.6.2"
  },
  "description": "An Ionic project",
  "cordova": {
    "plugins": {
      "phonegap-plugin-barcodescanner": {},
      "cordova-plugin-advanced-http": {}
    }
  }
}

矩形.ts

import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';

/*
  Generated class for the RestProvider provider.

  See https://angular.io/guide/dependency-injection for more info on providers
  and Angular DI.
*/
@Injectable()
export class RestProvider {

  apiUrl = 'https://jsonplaceholder.typicode.com';

  constructor(public http: HttpClient) {
    console.log('Hello RestProvider Provider');
  }

  getUsers() {
    return new Promise(resolve => {
      this.http.get(this.apiUrl+'/users').subscribe(data => {
        resolve(data);
      }, err => {
        console.log(err);
      });
    });
  }
}

【问题讨论】:

  • @sriharsha_bhat 那些实际上并没有解决我的问题,这就是我再次发布它的原因
  • @ivaro18 预览帖子没有解决方案。所以为什么将其标记为重复

标签: javascript angular typescript rxjs ionic3


【解决方案1】:

Angular 6 不适用于 RxJS 5.5,但适用于 RxJS 6。

你的 package.json 应该包含 "rxjs": "^6.1.0"

【讨论】:

  • 如何安装那个版本,我看到npmjs.com/package/rxjs/v/5.5.11 5.5.11 是最新的
  • 似乎没有更新:见github.com/ReactiveX/rxjs/releases。你可以npm i rxjs@6
  • 不工作我安装了最新版本
  • 返回 Typescript 错误模块 '"E:/AndroidProject/CompassApp/node_modules/rxjs/Observable"' 没有导出成员 'Observable'
  • 对 Observable 导入使用以下行: import { Observable } from 'rxjs';
猜你喜欢
  • 2018-09-01
  • 2017-12-29
  • 2019-02-02
  • 2018-10-20
  • 2020-08-09
  • 2018-11-29
  • 1970-01-01
  • 2020-02-08
  • 1970-01-01
相关资源
最近更新 更多