简体   繁体   English

Angular - 无法加载延迟加载的模块

[英]Angular - Lazy loaded module cannot be loaded

I have a problem with lazy loading of a module in Angular.我在 Angular 中延迟加载模块时遇到问题。 I have just upgrade from Angular 12 to Angular 13.我刚刚从 Angular 12 升级到 Angular 13。

There is one module that does not load correctly.有一个模块无法正确加载。 When the browser tries to download the module it gets a 404 .当浏览器尝试下载模块时,它会收到404 The module in question is biot-biot-module .有问题的模块是biot-biot-module When I look at the Lazy Chuck Files after compile, this module looks different from the others.当我在编译后查看 Lazy Chuck Files 时,这个模块看起来与其他模块不同。 It looks like it tries to bundle the css.看起来它试图捆绑 css。 The result is that src_app_biot_biot_module_ts.js is not generated.结果是没有生成src_app_biot_biot_module_ts.js

Any ideas why this happens?任何想法为什么会发生这种情况? As far as I can see, all the modules are configured in the same way.据我所见,所有模块都以相同的方式配置。

Initial Chunk Files                                    | Names                                    | Raw Size
main.js                                                | main                                     | 22.71 MB |
runtime.js                                             | runtime                                  | 15.89 kB |

Lazy Chunk Files                                       | Names                                    | Raw Size
src_app_biot_biot_module_ts.css, biot-biot-module.js   | biot-biot-module                         | 19.34 MB |
src_app_telegrams_telegrams_module_ts.js               | telegrams-telegrams-module               | 12.04 MB |
src_app_model-management_model-management_module_ts.js | model-management-model-management-module | 10.98 MB |
src_app_key-management_key-management_module_ts.js     | key-management-key-management-module     |  5.51 MB |
src_app_gum_gum_module_ts.js                           | gum-gum-module                           |  4.34 MB |
src_app_lora_lora_module_ts.js                         | lora-lora-module                         |  3.30 MB |

AppRoutingModule应用路由模块

const routes: Routes = [
  {
    path: 'home',
    component: HomeComponent,
  },
  {
    path: 'telegrams',
    loadChildren: () => import('./telegrams/telegrams.module').then(m => m.TelegramsModule),
  },
  {
    path: 'biot',
    loadChildren: () => import('./biot/biot.module').then(m => m.BiotModule),
  },
  {
    path: '',
    redirectTo: '/home',
    pathMatch: 'full'
  },
  {
    path: '**',
    redirectTo: '/home'
  }
];


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

Biot module生物模块

@NgModule({
  declarations: [
    // components
  ],
  imports: [
    CommonModule,
    SharedModule,
    BiotRoutingModule
  ]
})
export class BiotModule { }

Biot routing module Biot路由模块

const routes: Routes = [
  {
    path: '',
    component: BiotComponent,
    children: [
      {
        path: 'rules', component: RulesComponent,
      },
    ]
  }
];

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

i am having same issue, actually i am having this issue while using local api, i don't get this error while using live api我有同样的问题,实际上我在使用本地 api 时遇到了这个问题,我在使用实时 api 时没有收到这个错误

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM