Problem with loadChildren

I am having a problem with my Angular Ionic v5 App. Whenever I try to compile it with the command ionic cordova build android --prod, I get the following error:

ERROR in Cannot read properties of undefined (reading 'loadChildren')

I believe that the error lies within this module for the class ‘HomeLinkingPosPage’:

@NgModule({
    declarations: [HomeLinkingposPage],
    imports: [
        CommonModule,
        FormsModule,
        IonicModule,
        RouterModule.forChild([]),
        SharedModule
    ],
    providers: [{
        provide: ROUTES,
        useFactory: configHomeRoutes,
        deps: [AuthService],
        multi: true
    }]
})
export class HomeLinkingposPageModule {
}

export function configHomeRoutes(authService: AuthService) {
    let route: Routes;
    if (authService.currentRol.user_type === 'end_user') {
        route = [{
            path: '',
            loadChildren: () => import('../home-end-user/home-end-user.module').then(m => m.HomeEndUserPageModule),
        }];
    } else if (authService.currentRol.user_type === 'agent_user') {
        route = [{
            path: '',
            loadChildren: () => import('../home-agent-user/home-agent-user.module').then(m => m.HomeAgentUserPageModule),
        }];
    } else if (authService.currentRol.user_type === 'company_user') {
        route = [{
            path: '',
            loadChildren: () => import('../home-company-user/home-company-user.module').then(m => m.HomeCompanyUserPageModule),
        }];
    }

    return route;
}

This is the HomeLinkingposPage class:

import {AfterViewInit, Component} from '@angular/core';
import {Router} from '@angular/router';
import {AuthService} from 'src/app/providers/auth/auth.service';

@Component({
    selector: 'app-home-linkingpos',
    template: '',
})
export class HomeLinkingposPage implements AfterViewInit {

    constructor(private router: Router,
                public authService: AuthService) {

        if (this.authService.currentRol.user_type === 'end_user') {
            router.navigateByUrl('home-end-user');
        }

        if (this.authService.currentRol.user_type === 'agent_user') {
            router.navigateByUrl('home-agent-user');
        }

        if (this.authService.currentRol.user_type === 'company_user') {
            router.navigateByUrl('home-company-user');
        }
    }

    ngAfterViewInit() {
        if (this.authService.currentRol.user_type === 'end_user') {
            this.router.navigateByUrl('home-end-user');
        }

        if (this.authService.currentRol.user_type === 'agent_user') {
            this.router.navigateByUrl('home-agent-user');
        }

        if (this.authService.currentRol.user_type === 'company_user') {
            this.router.navigateByUrl('home-company-user');
        }
    }
}

And this is its route in the app’s app-routing.module:

{
        path: 'home-linkingpos',
        loadChildren: () => import('./linkingpos/home-linkingpos/home-linkingpos.module').then(m => m.HomeLinkingposPageModule),
    },

I can compile the app just fine when using ionic cordova build android but I always get the same loadChildren error when trying to compile for production. I am new to Ionic and have spent days trying to fix this issue to no avail.