4本机插件地理位置使我

4本机插件地理位置使我

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

问题描述

我正在尝试在ionic 4中使用离子本机插件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:\ Projects \ ionic \ prayers \ node_modules \ @ ionic-native \ geolocation'

./node_modules/@ionic-native/geolocation/index.js Module not found: Error: Can't resolve 'rxjs/Observable' in 'C:\Projects\ionic\prayers\node_modules\@ionic-native\geolocation'

这是我的依赖项:

"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版本.

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

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

就像您的其他ionic-native插件一样,因为根据 package .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/[email protected]

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

09-02 04:23