Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

194
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda