ReferenceError: Cannot access module before initialization ionic angular android 12
github-id01 opened this issue · 1 comments
@angular/core: ^16.0.0
@ionic/angular: ^7.0.0
cordova-android: 12.0.1
@angular/router": ^16.0.0
I have imported the PdfViewerModule in the module where I want to use, it is working fine. But it gives the error when running in android 12.
somepage-module.ts file:
import { EventEmitter, NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
import { IonicModule, NavParams } from '@ionic/angular';
import { ComponentsModule } from 'src/app/components/components.module';
import { SomePage } from './somepage'
import { SomePageRoutingModule } from './somepage-routing.module';
import { PipesModule } from 'src/app/pipes/pipes.module';
import { SwiperDirective } from '../../directives/swiper.directive'
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { PdfViewerModule } from 'ng2-pdf-viewer';
@NgModule({
imports: [
CommonModule,
FormsModule,
IonicModule,
PdfViewerModule,
SomePageRoutingModule,
ComponentsModule,
PipesModule,
],
declarations: [
SomePage,
SwiperDirective
],
schemas: [CUSTOM_ELEMENTS_SCHEMA],
providers: [NavParams, EventEmitter]
})
export class SomePageModule {}
somepage-routing-module.ts file:
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { SomePage } from './somepage';
const routes: Routes = [
{
path: '',
component: SomePage
}
];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule],
})
export class SomePageRoutingModule {}
app-routing-moudle.ts
import { NgModule } from '@angular/core';
import { PreloadAllModules, RouterModule, Routes } from '@angular/router';
import { SplashPage } from './pages/qwsplash/qwsplash';
export const routes: Routes = [
{ path: '', component: SplashPage },
{
path: 'pages/csplash',
loadChildren: () => import('./pages/splash/splash.module').then(m => m.SplashPageModule)
},
{
path: 'pages/home',
loadChildren: () => import('./pages/home/home.module').then(m => m.HomePageModule)
},
{
path: 'pages/somepage',
loadChildren: () => import('./pages/somepage/somepage.module').then( m => m.SomePageModule)
},
];
@NgModule({
imports: [
RouterModule.forRoot(routes, { preloadingStrategy: PreloadAllModules, enableTracing: true })
],
exports: [RouterModule]
})
export class AppRoutingModule {}
When I navigate to the page with this.navCtrl.navigateForward('pages/somepage', navigationOptions);
, it then gives the error:
ReferenceError: Cannot access module before initialization ionic angular android 12
what could be the possible reason ? I have used tools like madge and dpdm to check for circular dependency but none found. But dpdm did gave the following warning:
skip "node_modules/ng2-pdf-viewer/fesm2022/ng2-pdf-viewer.mjs", issuers: "src/app/app.module.ts", "src/app/pages/somepage/somepage.module.ts"
Alhamdulillah got the solution. Had to downgrade the ng2-pdf-viewer
version to 9.1.5 to make it work on android 12 as well. Not sure about the reason but Allah's mercy guided me through here.