ionic - RXJS 错误:rxjs_Observable__.Observable.combineLatest 不是函数

Posted

技术标签:

【中文标题】ionic - RXJS 错误:rxjs_Observable__.Observable.combineLatest 不是函数【英文标题】:ionic - RXJS error : rxjs_Observable__.Observable.combineLatest not a function 【发布时间】:2019-05-21 03:53:53 【问题描述】:

在我的 Ionic 3.9 应用程序中,我在浏览器中运行 ionic serve 时收到此错误:__WEBPACK_IMPORTED_MODULE_1_rxjs_Observable__.Observable.combineLatest is not a function

我遇到插件错误,因此我删除了 node_modules、yarn.lock,并通过 $ yarn install 重新安装了所有依赖项。

ERROR TypeError: __WEBPACK_IMPORTED_MODULE_1_rxjs_Observable__.Observable.combineLatest is not a function
    at NgxErrorDirective.ngOnInit (ngxerror.directive.js:40)
    at checkAndUpdateDirectiveInline (core.js:12369)
    at checkAndUpdateNodeInline (core.js:13893)

这是我的配置:

$ ionic info

Ionic:

   ionic (Ionic CLI)  : 4.6.0
   Ionic Framework    : ionic-angular 3.9.2
   @ionic/app-scripts : 3.2.1

Cordova:

   cordova (Cordova CLI) : 8.1.2 (cordova-lib@8.1.1)
   Cordova Platforms     : android 7.0.0, browser 5.0.4
   Cordova Plugins       : cordova-plugin-ionic-keyboard 2.1.2, (and 5 other plugins)

System:

   Android SDK Tools : 25.2.5 (/home/louisro/android-sdk-linux/)
   NodeJS            : v8.9.4 (/home/louisro/.nvm/versions/node/v8.9.4/bin/node)
   npm               : 5.6.0
   OS                : Linux 4.4

这是$ yarn install 给出的:

$ yarn install
yarn install v1.12.3
info No lockfile found.
[1/4] Resolving packages...
warning angularfire2@5.1.1: AngularFire has moved, we're now @angular/fire
warning cordova-browser > path-is-absolute@2.0.0: This package is no longer relevant as Node.js 0.12 is unmaintained.
warning cordova-plugin-ionic > @types/cordova-plugin-file-transfer@1.6.2: This is a stub types definition for cordova-plugin-file-transfer (https://github.com/apache/cordova-plugin-file-transfer). cordova-plugin-file-transfer provides its own type definitions, so you don't need @types/cordova-plugin-file-transfer installed!
warning @ionic/app-scripts > autoprefixer > browserslist@2.11.3: Browserslist 2 could fail on reading Browserslist >3.0 config used in other tools.
[2/4] Fetching packages...
info fsevents@1.2.4: The platform "linux" is incompatible with this module.
info "fsevents@1.2.4" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] Linking dependencies...
warning " > @angular/common@5.2.9" has incorrect peer dependency "rxjs@^5.5.0".
warning " > @angular/core@5.2.9" has incorrect peer dependency "rxjs@^5.5.0".
warning " > @angular/forms@5.2.9" has incorrect peer dependency "rxjs@^5.5.0".
warning " > @angular/http@5.2.9" has incorrect peer dependency "rxjs@^5.5.0".
warning " > @ionic-native/camera@4.18.0" has incorrect peer dependency "@ionic-native/core@^4.11.0".
warning " > @ionic-native/camera@4.18.0" has incorrect peer dependency "rxjs@^5.5.11".
warning " > @ionic-native/core@4.5.3" has incorrect peer dependency "rxjs@^5.0.1".
warning " > @ionic-native/email-composer@4.18.0" has incorrect peer dependency "@ionic-native/core@^4.11.0".
warning " > @ionic-native/email-composer@4.18.0" has incorrect peer dependency "rxjs@^5.5.11".
warning " > @ionic-native/fcm@4.18.0" has incorrect peer dependency "@ionic-native/core@^4.11.0".
warning " > @ionic-native/fcm@4.18.0" has incorrect peer dependency "rxjs@^5.5.11".
warning " > @ionic-native/geolocation@4.18.0" has incorrect peer dependency "@ionic-native/core@^4.11.0".
warning " > @ionic-native/geolocation@4.18.0" has incorrect peer dependency "rxjs@^5.5.11".
warning " > @ionic-native/http@4.18.0" has incorrect peer dependency "@ionic-native/core@^4.11.0".
warning " > @ionic-native/http@4.18.0" has incorrect peer dependency "rxjs@^5.5.11".
warning " > @ionic-native/push@4.18.0" has incorrect peer dependency "@ionic-native/core@^4.11.0".
warning " > @ionic-native/push@4.18.0" has incorrect peer dependency "rxjs@^5.5.11".
warning " > @ionic-native/splash-screen@4.5.3" has incorrect peer dependency "rxjs@^5.0.1".
warning " > @ionic-native/status-bar@4.5.3" has incorrect peer dependency "rxjs@^5.0.1".
warning " > angular-svg-round-progressbar@2.0.0" has incorrect peer dependency "@angular/compiler@^6.0.0".
warning " > angular-svg-round-progressbar@2.0.0" has incorrect peer dependency "@angular/common@^6.0.0".
warning " > angular-svg-round-progressbar@2.0.0" has incorrect peer dependency "@angular/core@^6.0.0".
warning " > angular-svg-round-progressbar@2.0.0" has unmet peer dependency "core-js@^2.4.1".
warning " > angular-svg-round-progressbar@2.0.0" has incorrect peer dependency "zone.js@^0.8.26".
warning "angularfire2 > @angular/fire@5.1.1" has incorrect peer dependency "@angular/common@>=6.0.0 <8".
warning "angularfire2 > @angular/fire@5.1.1" has incorrect peer dependency "@angular/core@>=6.0.0 <8".
warning "angularfire2 > @angular/fire@5.1.1" has incorrect peer dependency "@angular/platform-browser@>=6.0.0 <8".
warning "angularfire2 > @angular/fire@5.1.1" has incorrect peer dependency "@angular/platform-browser-dynamic@>=6.0.0 <8".
warning "firebase > @firebase/storage@0.2.4" has unmet peer dependency "@firebase/app-types@0.x".
warning "firebase > @firebase/functions@0.3.3" has unmet peer dependency "@firebase/app-types@0.x".
warning "firebase > @firebase/functions > @firebase/messaging-types@0.2.3" has unmet peer dependency "@firebase/app-types@0.x".
warning "firebase > @firebase/storage > @firebase/storage-types@0.2.3" has unmet peer dependency "@firebase/app-types@0.x".
warning "firebase > @firebase/database@0.3.7" has unmet peer dependency "@firebase/app-types@0.x".
warning "firebase > @firebase/database > @firebase/database-types@0.3.2" has unmet peer dependency "@firebase/app-types@0.x".
warning "firebase > @firebase/auth > @firebase/auth-types@0.5.0" has unmet peer dependency "@firebase/app-types@0.x".
warning "firebase > @firebase/firestore@0.9.0" has unmet peer dependency "@firebase/app-types@0.x".
warning "firebase > @firebase/messaging@0.3.7" has unmet peer dependency "@firebase/app-types@0.x".
warning "firebase > @firebase/firestore > @firebase/firestore-types@0.8.0" has unmet peer dependency "@firebase/app-types@0.x".
warning " > ng2-charts-x@2.0.6" has incorrect peer dependency "rxjs@^5.1.0".
warning " > ng2-charts-x@2.0.6" has unmet peer dependency "moment@^2.18.1".
[4/4] Building fresh packages...
success Saved lockfile.
Done in 72.88s.

【问题讨论】:

【参考方案1】:

正如纱线告诉你的那样:你有不正确的对等依赖关系。

我看到您正在尝试安装需要 @angular/common@&gt;=6.0.0@angular/fire@5.1.1 软件包。 这也意味着将您所有的 @angular/*rxjs 依赖项升级到 6.0.0 或更高版本。

您还应该注意到rxjs 6 和以前的版本之间有一些重大变化(您的 combineLatest 错误可能来自这里)。您也可以安装 rxjs-compat 以保持您的代码不变。

希望对你有帮助。

【讨论】:

我的 package.json 中有 :"angularfire2": "^5.0.0-rc.12" 那么为什么 yarn 会尝试安装 5.1.1 呢?注意:rxjs-compat 已经安装。 我无法升级到 Angular 6,因为它是 ionic 3 应用程序,适用于 Angular 5。我该怎么办?【参考方案2】:

看起来有问题Observable.combineLatest。如果不查看代码很难假设,但如果您导入 Observable,则更有可能您也需要像这样导入 combineLatest

import  Observable  from 'rxjs/Observable';
import 'rxjs/add/observable/combineLatest';

希望它有效。

【讨论】:

在我导入 rxjs/Observable 的角度组件中的任何地方,我都按照您的建议添加了 import combienlatest 行,但错误仍然存​​在 你能分享至少一个你的 combineLatest 你是如何使用的例子,所以我可能会得到一个线索,这样真的很难预测。 我没有明确使用它!就是这样。如果您查看我得到的错误,它来自 ngxerror.directive.js,实际上我在 html 中使用 rxjs 错误,如下所示:` 最少 6 个字符 `

以上是关于ionic - RXJS 错误:rxjs_Observable__.Observable.combineLatest 不是函数的主要内容,如果未能解决你的问题,请参考以下文章

Ionic 4 本机插件地理定位给了我“找不到模块:错误:无法解析 'rxjs/Observable'”

Ionic3 中的 Angular flex-layout... rxjs/operator 找不到?

ionic2 jpush

“void”类型上不存在属性“map”。在角度

我可以将 async/await Promises 与可观察的 RXJS 混合使用吗?

firebase 和 Ionic 2 上的降序 orderByChild()