Ionic 4 本机插件地理定位给了我“找不到模块:错误:无法解析 'rxjs/Observable'" [英] Ionic 4 native plugin geolocation gives me "Module not found: Error: Can't resolve 'rxjs/Observable'"

查看:20
本文介绍了Ionic 4 本机插件地理定位给了我“找不到模块:错误:无法解析 'rxjs/Observable'"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 ionic 4 中使用 ionic 原生插件 geolocation 但出现此错误:

I'm trying to use ionic native plugin geolocation in ionic 4 but I got a this error:

编译失败.

./node_modules/@ionic-native/geolocation/index.js 未找到模块:错误:无法解析rxjs/Observable"'C:Projectsionicprayers ode_modules@ionic-nativegeolocation'

./node_modules/@ionic-native/geolocation/index.js Module not found: Error: Can't resolve 'rxjs/Observable' in 'C:Projectsionicprayers ode_modules@ionic-nativegeolocation'

这是我的依赖:

"dependencies": {
    "@angular/common": "6.0.9",
    "@angular/core": "6.0.9",
    "@angular/forms": "6.0.9",
    "@angular/http": "6.0.9",
    "@angular/platform-browser": "6.0.9",
    "@angular/platform-browser-dynamic": "6.0.9",
    "@angular/router": "6.0.9",
    "@ionic-native/core": "5.0.0-beta.14",
    "@ionic-native/geolocation": "^4.11.0",
    "@ionic-native/splash-screen": "5.0.0-beta.14",
    "@ionic-native/status-bar": "5.0.0-beta.14",
    "@ionic/angular": "4.0.0-beta.0",
    "@ionic/ng-toolkit": "1.0.0",
    "@ionic/schematics-angular": "1.0.1",
    "cordova-plugin-geolocation": "^4.0.1",
    "core-js": "^2.5.3",
    "rxjs": "6.2.2",
    "zone.js": "^0.8.26"
  },

这是我使用的代码:-

app.module.ts

app.module.ts

import { Geolocation } from '@ionic-native/geolocation';
...
NgModule({
  declarations: [AppComponent],
  entryComponents: [],
  imports: [BrowserModule, IonicModule.forRoot(), AppRoutingModule],
  providers: [
    StatusBar,
    SplashScreen, Geolocation,
    { provide: RouteReuseStrategy, useClass: IonicRouteStrategy }
  ],
  bootstrap: [AppComponent]
})

home.ts

import { Geolocation } from '@ionic-native/geolocation';
...
constructor(private geolocation: Geolocation) {}

推荐答案

你已经安装了 rxjs 6.2.2 在导入语句发生变化的地方.

You have rxjs 6.2.2 installed where importing statements are changed.

稳定的 ionic-native 仍在使用 rxjs 5.x.

The stable ionic-native is still using rxjs 5.x.

您可以查看迁移指南这里.

您可以使用 rxjs-compat

npm i rxjs-compat --save

或者回到 5.x 版本.

Or go back to 5.x version.

另一种选择是将 @ionic-native/geolocation 版本更新为 5.0.0-beta14

Another option is to update @ionic-native/geolocation version to 5.0.0-beta14

像您的其他离子原生插件一样,因为根据 包.json,它应该使用 rxjs 6.x

like your other ionic-native plugins since according to the package.json, it should be using rxjs 6.x

npm i --save @ionic-native/geolocation@5.0.0-beta.14

这篇关于Ionic 4 本机插件地理定位给了我“找不到模块:错误:无法解析 'rxjs/Observable'"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆