Angular 13 Error: Type NgZone does not have 'ɵmod' property

1.1k views Asked by At

In my Angular 13 Ionic app, as soon as I add the NgZone to app.module.ts - I get this error:

core.mjs:1130 Uncaught Error: Type NgZone does not have 'ɵmod' property.

I tried following suggested solutions in github here and others, such as:

  • npm ic
  • Adding "postinstall": "ngcc" to package.json's scripts section.
  • Deleting the .angular/cache folder in my project

Nothing works. In app.module.ts:

import { NgModule, NgZone } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { IonicModule, IonicRouteStrategy } from '@ionic/angular';

@NgModule({
  declarations: [AppComponent],
  entryComponents: [],
  imports: [BrowserModule, 
    NgZone,
    IonicModule.forRoot(), 

I am consuming this in a service I'm calling upon application init:

import { Injectable, NgZone } from '@angular/core';
import {ActionPerformed, PushNotifications, PushNotificationSchema, Token} from '@capacitor/push-notifications';
import {  Capacitor } from '@capacitor/core';
import { ActivatedRoute,Router } from '@angular/router';

import { TigergraphService } from "./tigergraph.service";
import { get, set, remove } from './storage.service';

@Injectable({
  providedIn: 'root'
})
export class FbNotificationsReceiveService {

  constructor(private router: Router, public tgdb: TigergraphService, private zone: NgZone) { }
 
  initPush() {
    if (Capacitor.getPlatform() !== 'web') {
      this.registerPush();
    }
  }
 
  private registerPush() {
    PushNotifications.requestPermissions().then((permission) => {
      if (permission.receive === 'granted') {
        // Register with Apple / Google to receive push via APNS/FCM
        PushNotifications.register(); //Registers app to receive notifications
      } else {
        // No permission for push granted by user on iOS
      }
    });
 
    PushNotifications.addListener(
      'registration',
      async (token: Token) => {
        console.log('My token: ' + JSON.stringify(token));
        //This is the device token.
        set('device-token', token.value); //to be picked up in registration
        remove('curr-person'); //clear local store of current person in app init
        //var tg = new TgdbService;

        
        this.tgdb.runQuery("getPersonByDeviceId", {"DeviceId": token.value}).subscribe(
        res => {
          if(res == null){
            //No person found in DB - need registration routing
            console.log('No person found with DeviceID. Routing to registration');
            this.zone.run(() => {  //<<<---- USED HERE -------
              this.router.navigate(['registration']);
            });
          } else {
            //person exists in db
            console.log('TG Query Result PErson by DeviceID: ' + JSON.stringify(res) + ' firstName: ' + res[0].vPerson[0].attributes.firstName);
            set('curr-person', res[0].vPerson[0].attributes); //Store locally for use throughout the app
            console.log('curr-person just saved: ' + get('curr-person'));
            //Rout based on user type
          }
        },
        err => {
          console.log('TG Query Error: ' + err.description);
        }
    );
}

Any more ideas for me? Thank you!

0

There are 0 answers