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

ram*_*hin 6 geolocation rxjs ionic-native angular ionic4

我试图用离子本地插件geolocationionic 4,但我得到了这个错误:

编译失败.

./node_modules/@ionic-native/geolocation/index.js找不到模块:错误:无法解析'C:\ Projects\ionic\prayers \node_modules\@ ionic-native\geolocation'中的'rxjs/Observable'

这是我的依赖:

"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"
  },
Run Code Online (Sandbox Code Playgroud)

这是我使用的代码: -

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]
})
Run Code Online (Sandbox Code Playgroud)

home.ts

import { Geolocation } from '@ionic-native/geolocation';
...
constructor(private geolocation: Geolocation) {}
Run Code Online (Sandbox Code Playgroud)

Sur*_*Rao 7

您已rxjs 6.2.2安装导入语句已更改的位置.

该稳定的离子本土依然采用rxjs 5.x的.

您可以在此处查看迁移指南.

你可以使用rxjs-compat

npm i rxjs-compat --save
Run Code Online (Sandbox Code Playgroud)

或者回到5.x版本.

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

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

npm i --save @ionic-native/geolocation@5.0.0-beta.14
Run Code Online (Sandbox Code Playgroud)