Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

201
Vistas
Angular Lazy Loading Does Not Work in Production Mode

Before asking this question, I read all the similar questions in StackOverflow and tried all the solutions mentioned by other users but still stuck in this seemingly simple problem. Everything works fine in my local MacBook Air M1 while developing but after producing the production build it is not working in my Windows Server 2019 Standard which is my production server. The following is the simple version of my source code.

AppModule:

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';

@NgModule({
  declarations: [AppComponent],
  imports: [
    BrowserModule,
    AppRoutingModule
  ],
  bootstrap: [AppComponent]
})
export class AppModule {}

AppRoutingModule:

import { NgModule } from "@angular/core";
import { RouterModule, Routes } from "@angular/router";

const routes: Routes = [
  { path: "", pathMatch: "full", redirectTo: "/test" },
  {
    path: "test",
    loadChildren: () =>
      import("@project-name/test").then((m) => m.TestModule),
  },
];

@NgModule({
  imports: [RouterModule.forRoot(routes)],
  exports: [RouterModule],
})
export class AppRoutingModule {}

app.component.html:

<h1>I am app component!</h1>
<router-outlet></router-outlet>

TestModule:

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { RouterModule } from '@angular/router';
import { TestComponent } from './test.component';

@NgModule({
  imports: [CommonModule, RouterModule.forChild([{ path: '', component: TestComponent }])],
  declarations: [TestComponent]
})
export class TestModule {}

TestComponent:

<h1>I am a test component!</h1>

In production server, when I hit the localhost/my-project I will the test component successfully loaded; but when I hit the localhost/my-project/test I see 404 Not Found and nothing is shown in the browser. I should mention that I have hosted the built app on nginx/1.19.10 and I am developing the app using Nx monorepo.

What I have tried so far but the problem not solved yet:

  • Checking import paths to be consistent and not different in the project (e.g., "@project-name/test")
  • Setting tsconfig.compilerOptions to esnext
  • Turning of the build optimiser and aot using both ng build --prod --build-optimizer=false --aot=false command and configuration section in the angular.json
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda