title: Capacitor BackgroundTask Err: 'Cannot read property 'beforeExit' of undefined'
body: <p>I have set up a background Task as shown in the Capacitor Docs and i get this Error.
  <a href="https://capacitorjs.com/docs/v2/apis/background-task" rel="nofollow noreferrer">https://capacitorjs.com/docs/v2/apis/background-task</a></p>
  <p>The Error occurs upon closing the Application</p>
  <pre><code>TypeError: Cannot read property 'beforeExit' of undefined
      at Object.callback (main.js:76)
      at Object.cap.fromNative ((index):434)
      at &lt;anonymous&gt;:1:18
  </code></pre>
  <p>My Background task Code</p>
  <pre><code>import { Component, OnInit } from '@angular/core'
  import { DeviceService } from 'repapp-common-lib'
  import { Plugins } from '@capacitor/core';
  
  const { App, BackgroundTask, LocalNotifications } = Plugins;
  
  export class AppComponent implements OnInit {
  
  constructor(){}
  
   ngOnInit() {
    App.addListener('appStateChange', state =&gt; {
     if (!state.isActive) {
  
      let taskId = BackgroundTask.beforeExit(async () =&gt; {
  
        var start = new Date().getTime();
        for (var i = 0; i &lt; 1e18; i++) {
          if (new Date().getTime() - start &gt; 20000) {
            break;
          }
        }
        BackgroundTask.finish({
          taskId,
        });
      });
     }
    });
   }
  }
  </code></pre>