HaylLtd / cordova-background-geolocation-plugin

Background and foreground geolocation plugin for Cordova.
Apache License 2.0
57 stars 66 forks source link

Can't resolve 'cordova/exec' / Can't resolve 'cordova/channel' #150

Closed aaadipop closed 1 year ago

aaadipop commented 1 year ago

Describe the bug

I installed the plugin, imported in angular controller, and try to follow the example from docs but I got the following erorrs: Error: Can't resolve 'cordova/exec' and Error: Can't resolve 'cordova/channel'

To Reproduce Steps to reproduce the behavior:

  1. Install the plugin: cordova plugin add cordova-background-geolocation-plugin
  2. import it on angular component: import BackgroundGeolocation from 'cordova-background-geolocation-plugin';
  3. try to start tracking / configure:

    platform.ready().then(() => {
    
      // refresh events on platform resume
      this.platform.resume.subscribe(() => {
        this.doRefresh(null);
      });
    
      BackgroundGeolocation.on('authorization', function(status) {
       console.log('[INFO] BackgroundGeolocation authorization status: ' + status);
       if (status !== BackgroundGeolocation.AUTHORIZED) {
         // we need to set delay or otherwise alert may not be shown
         setTimeout(function() {
           var showSettings = confirm('App requires location tracking permission. Would you like to open app settings?');
           if (showSettings) {
             return BackgroundGeolocation.showAppSettings();
           }
         }, 1000);
       }
     });
    
    });
    
    // BackgroundGeolocation.configure({
    //   locationProvider: BackgroundGeolocation.ACTIVITY_PROVIDER,
    //   desiredAccuracy: BackgroundGeolocation.HIGH_ACCURACY
    // });
    
    }

the error:

[ng] ✖ Failed to compile.
[ng]
[ng] ./node_modules/cordova-background-geolocation-plugin/www/BackgroundGeolocation.js:12:11-34 - Error: Module not found: Error: Can't resolve 'cordova/exec' in '/Users/padi/git/sls/sls-mobile/node_modules/cordova-background-geolocation-plugin/www'
[ng]
[ng] ./node_modules/cordova-background-geolocation-plugin/www/BackgroundGeolocation.js:13:14-40 - Error: Module not found: Error: Can't resolve 'cordova/channel' in '/Users/padi/git/sls/sls-mobile/node_modules/cordova-background-geolocation-plugin/www'

Expected behavior Start tracking

Smartphone (please complete the following information):

HarelM commented 1 year ago

I don't think this is the right way to import this plugin. Try the following example https://github.com/IsraelHikingMap/Site/blob/015d6780a2f9c08440ef51f18231ed81147af638/IsraelHiking.Web/src/application/services/geo-location.service.ts

aaadipop commented 1 year ago

@HarelM great, thanks a lot! :)