Error using Geofence

I am trying to add geofence to one of my apps. Following the instructions in https://ionicframework.com/docs/native/geofence/, I added the requested plugin:

  • $ ionic cordova plugin add cordova-plugin-geofence
  • $ npm install --save @ionic-native/geofence
    After this operation, I am no more able to run the app on Android platform:

Running app-scripts build: --platform android --target cordova
[18:41:41] build dev started …
[18:41:41] clean started …
[18:41:41] clean finished in 16 ms
[18:41:41] copy started …
[18:41:41] deeplinks started …
[18:41:41] deeplinks finished in 168 ms
[18:41:41] transpile started …
[18:41:48] transpile finished in 6.81 s
[18:41:48] preprocess started …
[18:41:48] preprocess finished in 16 ms
[18:41:48] webpack started …
[18:41:48] copy finished in 7.53 s
[18:41:56] webpack finished in 8.24 s
[18:41:56] sass started …
[18:41:59] sass finished in 2.35 s
[18:41:59] postprocess started …
[18:41:59] postprocess finished in 16 ms
[18:41:59] lint started …
[18:41:59] build dev finished in 17.97 s

cordova build android
(node:5900) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: Cannot find module '…/cordova/platform_metadata’

This is my package.json:

{
“name”: “ClientIonicProject”,
“version”: “0.0.1”,
“author”: “Ionic Framework”,
“homepage”: “http://ionicframework.com/”,
“private”: true,
“scripts”: {
“clean”: “ionic-app-scripts clean”,
“build”: “ionic-app-scripts build”,
“lint”: “ionic-app-scripts lint”,
“ionic:build”: “ionic-app-scripts build”,
“ionic:serve”: “ionic-app-scripts serve”
},
“dependencies”: {
@angular/common”: “^5.0.1”,
@angular/compiler”: “^5.0.1”,
@angular/compiler-cli”: “^5.0.1”,
@angular/core”: “^5.0.1”,
@angular/forms”: “^5.0.1”,
@angular/http”: “^5.0.1”,
@angular/platform-browser”: “^5.0.1”,
@angular/platform-browser-dynamic”: “^5.0.1”,
@ionic-native/app-version”: “^4.4.0”,
@ionic-native/core”: “4.3.3”,
@ionic-native/geofence”: “^4.7.0”,
@ionic-native/geolocation”: “^4.4.0”,
@ionic-native/http”: “^4.4.0”,
@ionic-native/in-app-browser”: “^4.4.0”,
@ionic-native/launch-navigator”: “^4.4.0”,
@ionic-native/network”: “^4.5.2”,
@ionic-native/splash-screen”: “4.3.3”,
@ionic-native/status-bar”: “4.3.3”,
@ionic-native/text-to-speech”: “^4.4.0”,
@ionic/storage”: “^2.1.3”,
@ngx-translate/core”: “^8.0.0”,
@ngx-translate/http-loader”: “^2.0.0”,
“cordova-android”: “6.3.0”,
“cordova-plugin-actionsheet”: “^2.3.3”,
“cordova-plugin-add-swift-support”: “^1.6.0”,
“cordova-plugin-advanced-http”: “^1.11.1”,
“cordova-plugin-app-version”: “^0.1.9”,
“cordova-plugin-compat”: “^1.2.0”,
“cordova-plugin-device”: “^1.1.4”,
“cordova-plugin-dialogs”: “^2.0.1”,
“cordova-plugin-file”: “^6.0.1”,
“cordova-plugin-geofence”: “^0.7.0”,
“cordova-plugin-geolocation”: “^3.0.0”,
“cordova-plugin-inappbrowser”: “^1.7.2”,
“cordova-plugin-ionic”: “^3.1.3”,
“cordova-plugin-ionic-webview”: “^1.2.1”,
“cordova-plugin-network-information”: “^1.3.4”,
“cordova-plugin-tts”: “^0.2.3”,
“cordova-plugin-whitelist”: “^1.3.1”,
“cordova-sqlite-storage”: “^2.3.1”,
“es6-promise-plugin”: “^4.2.2”,
“ionic-angular”: “3.9.2”,
“ionic-plugin-keyboard”: “^2.2.1”,
“ionicons”: “3.0.0”,
“rxjs”: “5.5.2”,
“sw-toolbox”: “3.6.0”,
“uk.co.workingedge.phonegap.plugin.launchnavigator”: “^4.2.0”,
“zone.js”: “0.8.18”
},
“devDependencies”: {
@ionic/app-scripts”: “3.1.0”,
“typescript”: “2.4.2”
},
“description”: “An Ionic project”,
“cordova”: {
“plugins”: {
“cordova-plugin-tts”: {},
“cordova-plugin-app-version”: {},
“cordova-plugin-geolocation”: {
“GEOLOCATION_USAGE_DESCRIPTION”: “To locate you”
},
“cordova-plugin-inappbrowser”: {},
“uk.co.workingedge.phonegap.plugin.launchnavigator”: {},
“cordova-plugin-advanced-http”: {},
“ionic-plugin-keyboard”: {},
“cordova-plugin-whitelist”: {},
“cordova-plugin-device”: {},
“cordova-plugin-ionic-webview”: {},
“cordova-plugin-network-information”: {},
“cordova-sqlite-storage”: {},
“cordova-plugin-geofence”: {}
},
“platforms”: [
“android”
]
}
}

I tried to completely delete all the folders except src and resources, but nothing changed.
Any help?
Best regards.

I reply to myself.
A possible workaround is to change the files

  • plugins\cordova-plugin-add-swift-support\src\add-swift-support.js
  • node_modules\cordova-plugin-add-swift-support\src\add-swift-support.js
//var platformMetadata = context.requireCordovaModule(‘cordova-lib/src/cordova/platform_metadata’); //old
var platformMetadata = context.requireCordovaModule(‘cordova-lib/src/cordova/project_metadata’); //new

How did you get the geofence to work in the first place?
Would you be willing to share your src code?

I was able to compile, but, as I show in Geofencing no notifications, it didn’t work for me, no notification.

this is a bug of the depending plugin ‘cordova-plugin-add-swift-support’. remove and reinstall ‘cordova-plugin-add-swift-support’ (upgrade to version ^1.7.2) solves the problem
see terikon/cordova-plugin-photo-library#124

I have also facing same issue. @Jingzhou @fpagano. I have tried many way still issue not resolved. Can you help me.