Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReferenceError: Cannot access module before initialization ionic angular android 12 #1071

Open
github-id01 opened this issue Mar 12, 2024 · 1 comment

Comments

@github-id01
Copy link

@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"

@github-id01
Copy link
Author

github-id01 commented Mar 14, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant