我正在尝试使用Cordova BackgroundGeolocation插件构建一个Ionic
位置跟踪应用程序:
https://ionicframework.com/docs/native/background-geolocation
不幸的是,由于我安装了插件,因此遇到以下错误:
Uncaught TypeError: Object(...) is not a function
at index.js:717
at Module../node_modules/@ionic-native/background-geolocation/index.js
(index.js:975)
at __webpack_require__ (bootstrap:83)
at Module../src/app/app.module.ts (app.component.ts:15)
at __webpack_require__ (bootstrap:83)
at Module../src/main.ts (main.ts:1)
at __webpack_require__ (bootstrap:83)
at Object.0 (main.ts:12)
at __webpack_require__ (bootstrap:83)
at checkDeferredModules (bootstrap:45)
app.module.ts
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { RouteReuseStrategy } from '@angular/router';
import { IonicModule, IonicRouteStrategy } from '@ionic/angular';
import { SplashScreen } from '@ionic-native/splash-screen/ngx';
import { StatusBar } from '@ionic-native/status-bar/ngx';
import { AppComponent } from './app.component';
import { AppRoutingModule } from './app-routing.module';
import { Toast } from '@ionic-native/toast/ngx';
import { HttpClientModule } from '@angular/common/http';
import { TabsPage } from './tabs/tabs.page';
import { environment } from '../environments/environment';
import { AngularFirestoreModule } from 'angularfire2/firestore';
import { AngularFireAuth } from 'angularfire2/auth';
import { AuthenticateService } from './authentication.service';
import { AngularFireAuthModule } from '@angular/fire/auth';
import { Geolocation } from '@ionic-native/geolocation/ngx';
import { NativeGeocoder } from '@ionic-native/native-geocoder/ngx';
import { BackgroundGeolocation } from '@ionic-native/background-geolocation';
import * as firebase from 'firebase';
firebase.initializeApp(environment.firebase);
@NgModule({
declarations: [AppComponent],
entryComponents: [],
imports: [BrowserModule,
IonicModule.forRoot(),
AppRoutingModule,
AngularFirestoreModule,
AngularFireAuthModule,
HttpClientModule
],
providers: [
StatusBar,
SplashScreen,
{ provide: RouteReuseStrategy, useClass: IonicRouteStrategy },
AngularFireAuth,
TabsPage,
AuthenticateService,
Toast,
Geolocation,
NativeGeocoder,
BackgroundGeolocation
],
bootstrap: [AppComponent]
})
export class AppModule { }
package.json
{
"name": "ionic3-barcodev4",
"version": "0.0.1",
"author": "Ionic Framework",
"homepage": "https://ionicframework.com/",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"@angular-devkit/build-angular": "^0.803.21",
"@angular/common": "^8.2.14",
"@angular/core": "^8.2.14",
"@angular/forms": "^8.2.14",
"@angular/http": "^7.2.15",
"@angular/platform-browser": "^8.2.14",
"@angular/platform-browser-dynamic": "^8.2.14",
"@angular/router": "^8.2.14",
"@ionic-native/background-geolocation": "^4.20.0",
"@ionic-native/barcode-scanner": "^5.16.0",
"@ionic-native/core": "^5.18.0",
"@ionic-native/geolocation": "^5.18.0",
"@ionic-native/google-analytics": "^5.17.0",
"@ionic-native/native-geocoder": "^5.18.0",
"@ionic-native/network": "^5.16.0",
"@ionic-native/splash-screen": "^5.16.0",
"@ionic-native/status-bar": "^5.16.0",
"@ionic-native/toast": "^5.16.0",
"@ionic/angular": "^4.11.4",
"@ionic/pro": "2.0.4",
"@mauron85/cordova-plugin-background-geolocation": "^3.1.0",
"angularfire2": "^5.2.1",
"cordova-android": "7.1.4",
"cordova-ios": "^5.1.1",
"cordova-plugin-add-swift-support": "^2.0.2",
"cordova-plugin-device": "^2.0.2",
"cordova-plugin-geolocation": "4.0.1",
"cordova-plugin-ionic-keyboard": "2.0.5",
"cordova-plugin-ionic-webview": "4.0.1",
"cordova-plugin-nativegeocoder": "^3.2.2",
"cordova-plugin-network-information": "2.0.2",
"cordova-plugin-splashscreen": "^5.0.2",
"cordova-plugin-statusbar": "^2.4.2",
"cordova-plugin-whitelist": "^1.3.3",
"cordova-plugin-x-toast": "2.7.2",
"core-js": "^2.6.10",
"firebase": "^5.11.1",
"moment": "^2.24.0",
"rxjs": "~6.5.3",
"rxjs-compat": "^6.5.3",
"zone.js": "~0.9.1"
},
"devDependencies": {
"@angular-devkit/architect": "~0.12.3",
"@angular-devkit/core": "^7.2.4",
"@angular-devkit/schematics": "^7.2.4",
"@angular/cli": "^8.3.21",
"@angular/compiler": "^8.2.14",
"@angular/compiler-cli": "^8.2.14",
"@angular/language-service": "^8.2.14",
"@ionic/angular-toolkit": "^1.4.1",
"@ionic/lab": "1.0.24",
"@types/jasmine": "~2.8.8",
"@types/jasminewd2": "^2.0.8",
"@types/node": "~10.12.0",
"codelyzer": "~4.5.0",
"jasmine-core": "~2.99.1",
"jasmine-spec-reporter": "~4.2.1",
"karma": "^4.4.1",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "^2.0.6",
"karma-jasmine": "~1.1.2",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.4.0",
"ts-node": "~8.0.0",
"tslint": "~5.12.0",
"typescript": "~3.5.3"
},
"description": "An Ionic project",
"cordova": {
"plugins": {
"cordova-plugin-whitelist": {},
"cordova-plugin-statusbar": {},
"cordova-plugin-device": {},
"cordova-plugin-splashscreen": {},
"cordova-plugin-ionic-webview": {
"ANDROID_SUPPORT_ANNOTATIONS_VERSION": "27.+"
},
"cordova-plugin-x-toast": {},
"cordova-plugin-ionic-keyboard": {},
"cordova-plugin-geolocation": {
"GEOLOCATION_USAGE_DESCRIPTION": "To track your walks"
},
"cordova-plugin-network-information": {},
"cordova-plugin-nativegeocoder": {}
},
"platforms": [
"android"
]
}
}