Ionic 4 native plugin geolocation gives me "Module not found: Error: Can't resolve 'rxjs/Observable'"
Ionic 4 native plugin geolocation gives me "Module not found: Error: Can't resolve 'rxjs/Observable'"
我正在尝试在 ionic 4
中使用 ionic native 插件 geolocation
但我遇到了这个错误:
Failed to compile.
./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
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
安装了更改导入语句的地方。
稳定的ionic-native仍在使用rxjs 5.x。
您可以查看迁移指南here。
您可以使用 rxjs-compat
npm i rxjs-compat --save
或返回 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
我遇到了同样的问题,在将 Geolocation
升级到 5.0.0-beta.14
时,我还必须将导入路径更新为:
import { Geolocation } from "@ionic-native/geolocation/ngx";
OBS:对于 UniqueDeviceID
等其他导入,我还必须在导入路径中添加 /ngx
后缀。
我认为由于 Angular.
的第 6 版,此后缀是必需的
我正在尝试在 ionic 4
中使用 ionic native 插件 geolocation
但我遇到了这个错误:
Failed to compile.
./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
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
安装了更改导入语句的地方。
稳定的ionic-native仍在使用rxjs 5.x。
您可以查看迁移指南here。
您可以使用 rxjs-compat
npm i rxjs-compat --save
或返回 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
我遇到了同样的问题,在将 Geolocation
升级到 5.0.0-beta.14
时,我还必须将导入路径更新为:
import { Geolocation } from "@ionic-native/geolocation/ngx";
OBS:对于 UniqueDeviceID
等其他导入,我还必须在导入路径中添加 /ngx
后缀。
我认为由于 Angular.