【问题标题】:Angular 5 to 6 Without Backward Compatible RxJS (rxjs-compat)Angular 5 到 6 没有向后兼容的 RxJS (rxjs-compat)
【发布时间】:2020-01-10 20:24:52
【问题描述】:

我参与了将项目从 Angular 5.2.11 迁移到 6.0.0 的相当艰巨的任务,而且我在使用 RxJS 6(Angular > 6 需要它)时遇到了一些困难。例如,我得到了这个和许多其他类似的:

ERROR in node_modules/angularfire2/auth/auth.d.ts(3,10): error TS2305: Module '"/Users/jadam/brightwater2/node_modules/rxjs/Observable"' has no exported member 'Observable'.

安装 rxjs-compat 显然可以解决这个问题,但我想知道如果没有它是否可以解决这些类型的错误。

这个topic 提出了同样的问题,但从未得到满意的答案。

我已将 import { Observable } from 'rxjs/Observable' 更改为 'import { Observable } from 'rxjs' 无济于事。 (顺便说一句,正如有人在链接线程和其他人中建议的那样,这两种方式都不起作用。)

package.json 在这里:

  "name": "differ",
  "version": "0.0.0",
  "license": "MIT",
  "angular-cli": {},
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "lint": "tslint \"src/**/*.ts\" --project src/tsconfig.app.json --type-check && tslint \"e2e/**/*.ts\" --project e2e/tsconfig.json --type-check",
    "test": "ng test",
    "pree2e": "webdriver-manager update --standalone false --gecko false",
    "e2e": "protractor"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "6.0.0",
    "@angular/common": "6.0.0",
    "@angular/compiler": "6.0.0",
    "@angular/compiler-cli": "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/platform-server": "6.0.0",
    "@angular/router": "6.0.0",
    "@types/node": "^6.0.73",
    "angular2-moment": "^1.1.0",
    "angularfire2": "^4.0.0-rc.0",
    "child-process-promise": "^2.2.1",
    "core-js": "^2.4.1",
    "diff": "^3.2.0",
    "elasticsearch": "^12.1.3",
    "firebase": "^3.6.10",
    "firebase-admin": "^4.1.2",
    "firebase-token-generator": "^2.0.0",
    "identicon.js": "^2.2.1",
    "marked": "^0.3.5",
    "ng-diff-match-patch": "^3.0.1",
    "ng2-charts": "^1.6.0",
    "ng2-scroll-to": "^1.0.7",
    "rxjs": "^6.0.0",
    "showdown": "^1.6.4",
    "ts-helpers": "^1.1.1",
    "ts-md5": "^1.2.0",
    "zone.js": "^0.7.6"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "^0.6.8",
    "@angular/cli": "6.0.0",
    "@angular/compiler-cli": "^4.4.4",
    "@types/jasmine": "2.5.38",
    "@types/node": "^6.0.42",
    "@types/showdown": "^1.4.31",
    "codelyzer": "~2.0.0-beta.1",
    "eslint-config-google": "^0.9.1",
    "jasmine-core": "2.5.2",
    "jasmine-spec-reporter": "2.5.0",
    "karma": "1.2.0",
    "karma-chrome-launcher": "^2.0.0",
    "karma-cli": "^1.0.1",
    "karma-jasmine": "^1.0.2",
    "karma-remap-istanbul": "^0.2.1",
    "protractor": "~4.0.13",
    "ts-node": "1.2.1",
    "tslint": "^4.3.0",
    "typescript": "^2.7.2"
  },
  "jspm": {
    "dependencies": {},
    "devDependencies": {
      "typescript": "npm:typescript@^2.0.7"
    }
  }
}

【问题讨论】:

  • angularfire2@4.0.0-rc.0 不支持 rxjs 6. 您必须将 angularfire2 升级到在 @angular/fire 下发布的版本 5。

标签: angular typescript rxjs


【解决方案1】:

删除您的节点模块文件夹并重新运行 NPM INSTALL > npm install 并使用 import { Observable } from 'rxjs';

【讨论】:

  • 这个我其实已经做过了,但是为了彻底,我会再试一次。
  • 是的,这也不起作用。我什至用npm cache clean --force 强制清理缓存。
  • 你删除了你的 package-lock.json 吗?如果没有,请清除并重试,请先生。
  • 好的,所以删除 node_modules、删除锁定文件和清理缓存最初会出现这个error,但重新安装 rxjs 6.0.0 解决了这个问题......我又回到了@987654325 @.
  • 现在你已经安装了 rxjs 6 并且可以正常工作了 import { Observable } from 'rxjs';
猜你喜欢
  • 2018-10-21
  • 1970-01-01
  • 2018-10-17
  • 2019-03-24
  • 2021-01-16
  • 1970-01-01
  • 2018-12-19
  • 2018-10-16
  • 1970-01-01
相关资源
最近更新 更多