29

我将我的 Angular 项目和所有依赖项更新到最新版本。没有太多麻烦,我解决了大部分依赖问题,但我仍然坚持使用 RxJS。这是我的 package.json:

  "dependencies": {
    "@angular-devkit/build-angular": "^0.6.0",
    "@angular/animations": "^6.0.0",
    "@angular/common": "^6.0.0",
    "@angular/compiler": "^6.0.0",
    "@angular/core": "^6.0.0",
    "@angular/forms": "^6.0.0",
    "@angular/http": "^6.0.0",
    "@angular/platform-browser": "^6.0.0",
    "@angular/platform-browser-dynamic": "^6.0.0",
    "@angular/router": "^6.0.0",
    "angular-bootstrap-md": "^6.0.1",
    "core-js": "^2.5.5",
    "font-awesome": "^4.7.0",
    "rxjs": "^6.1.0",
    "zone.js": "^0.8.26"
  },
  "devDependencies": {
    "@angular/cli": "~6.0.0",
    "@angular/compiler-cli": "^6.0.0",
    "@angular/language-service": "6.0.0",
    "@types/jasmine": "~2.8.3",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "~6.0.60",
    "codelyzer": "^4.0.1",
    "electron": "^1.8.3",
    "jasmine-core": "~2.8.0",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~2.0.2",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "^1.4.2",
    "karma-jasmine": "~1.1.2",
    "karma-jasmine-html-reporter": "^1.0.0",
    "protractor": "~5.3.1",
    "ts-node": "~6.0.2",
    "tslint": "~5.10.0",
    "typescript": "~2.7.2"

我只从 RxJS 导入两个模块:

import { fromPromise } from 'rxjs/observable/fromPromise';
import { Subscription } from 'rxjs/Subscription';

他们都给出了同样的错误:

    [ts] Module '"***/node_modules/rxjs/Subscription"' has no exported
 member 'Subscription'.

对于fromPromise. 这是我得到的错误消息Subscribtion.d.ts(我没有以任何方式修改代码)

在此处输入图像描述

更新:

下面的答案解决了 Subscription 的问题,但fromPromise即使导出正确,仍然会出现同样的问题:

export * from 'rxjs-compat/observable/fromPromise';

在此处输入图像描述

4

4 回答 4

51

RxJS 6 有很多重大变化。例如,原型方法为

myObservable.map(data => data * 2)

将不再工作,必须替换为

myObservable.pipe(map(data => data * 2))

所有细节都可以在这里找到:https ://github.com/ReactiveX/rxjs/blob/master/docs_app/content/guide/v6/migration.md


在您修复所有重大更改之前,您可以使用rxjs-compat( https://github.com/ReactiveX/rxjs/tree/master/compat ) 使旧代码再次工作。

这个包需要向后兼容 RxJS 版本 6 之前的版本。它包含将运算符添加到的导入 Observable.prototype和创建方法到Observable.

输入这个来安装它:

npm install -s rxjs-compat
于 2018-05-04T13:33:23.503 回答
10

我希望您的问题将使用以下语句解决 import Subscription from 'rxjs'

于 2019-07-30T06:07:25.157 回答
2

You can fix it with this:

import {from} from 'rxjs';

And, instead of: return Observable.fromPromise(new Promise((resolve, reject) => {

Now just do:

return from(new Promise((resolve, reject) => {

The same applies to Observable.of

于 2019-01-09T20:17:53.147 回答
0

afaik Angular 6 和 rxjs 6 尚不兼容,对于他们创建的兼容性https://www.npmjs.com/package/rxjs-compat你必须安装

[更新] fromPromise 现在是“来自”。见这里:https ://github.com/ReactiveX/rxjs/issues/3525

于 2018-05-04T13:34:40.080 回答