Angular 延迟加载问题:加载区块0失败

Angular 延迟加载问题:加载区块0失败,angular,lazy-loading,Angular,Lazy Loading,中的组件--lazy.module.ts const routes: Routes = [ { path: 'memberdetails', component: MemberDetailsComponent }, { path: 'leaves', component: LeavemanagementComponent }, { path: 'attendance', component: AttendanceComponent } ]; const routes: R

中的组件--lazy.module.ts

 const routes: Routes = [
   { path: 'memberdetails', component: MemberDetailsComponent },
   { path: 'leaves', component: LeavemanagementComponent },
  { path: 'attendance', component: AttendanceComponent }
 ];
 const routes: Routes = [
   { path: 'lazy', loadChildren: './lazy.module#LazyModule'},
 ];
app-routing.module.ts

 const routes: Routes = [
   { path: 'memberdetails', component: MemberDetailsComponent },
   { path: 'leaves', component: LeavemanagementComponent },
  { path: 'attendance', component: AttendanceComponent }
 ];
 const routes: Routes = [
   { path: 'lazy', loadChildren: './lazy.module#LazyModule'},
 ];
它在本地工作,但是在托管它之后,当我点击上面的任何链接时,我得到了这个错误

vendor.05d559e….bundle.js:1 ERROR Error: Uncaught (in promise): Error: 
Loading chunk 0 failed.
Error: Loading chunk 0 failed.
at HTMLScriptElement.r (inline.9786b27….bundle.js:1)
at HTMLScriptElement.L (polyfills.1a7da64….bundle.js:1)
at e.invokeTask (polyfills.1a7da64….bundle.js:1)
at Object.onInvokeTask (vendor.05d559e….bundle.js:1)
at e.invokeTask (polyfills.1a7da64….bundle.js:1)
at r.runTask (polyfills.1a7da64….bundle.js:1)
at t.invokeTask [as invoke] (polyfills.1a7da64….bundle.js:1)
at h (polyfills.1a7da64….bundle.js:1)
at HTMLScriptElement.d (polyfills.1a7da64….bundle.js:1)
at HTMLScriptElement.r (inline.9786b27….bundle.js:1)
at HTMLScriptElement.L (polyfills.1a7da64….bundle.js:1)
at e.invokeTask (polyfills.1a7da64….bundle.js:1)
at Object.onInvokeTask (vendor.05d559e….bundle.js:1)
at e.invokeTask (polyfills.1a7da64….bundle.js:1)
at r.runTask (polyfills.1a7da64….bundle.js:1)
at t.invokeTask [as invoke] (polyfills.1a7da64….bundle.js:1)
at h (polyfills.1a7da64….bundle.js:1)
at HTMLScriptElement.d (polyfills.1a7da64….bundle.js:1)
at u (polyfills.1a7da64….bundle.js:1)
at u (polyfills.1a7da64….bundle.js:1)
at polyfills.1a7da64….bundle.js:1
at e.invokeTask (polyfills.1a7da64….bundle.js:1)
at Object.onInvokeTask (vendor.05d559e….bundle.js:1)
at e.invokeTask (polyfills.1a7da64….bundle.js:1)
at r.runTask (polyfills.1a7da64….bundle.js:1)
at o (polyfills.1a7da64….bundle.js:1)
at t.invokeTask [as invoke] (polyfills.1a7da64….bundle.js:1)
at h (polyfills.1a7da64….bundle.js:1)
文件夹结构:


清理缓存或使用CTRL+Shift+R组合键,然后重试

CTRL+Shift+R硬重新加载在我的特殊情况下有帮助,因为我的问题是我做了设计更改,需要硬重新加载。不确定它是否能在所有情况下解决此错误。

在我的情况下
广告阻断程序的扩展造成了这个问题。一旦我禁用了它。问题解决了

我们最近在Angular builds中也遇到了同样的问题。我们使用的是角度7+。 原因确实是缓存。但在我们的例子中,它是基于CloudFront的缓存。因此,我的建议是,如果您面临任何此类问题,请清理所有类型的缓存,如:

  • 特定于域(例如CloudFlare)
  • 任何CDN缓存-例如;AWS的CloudFront—稍后我们实现了一个解决方案,任何新的部署管道都将自动刷新CloudFront缓存。现在不需要手动清除缓存
  • 基于Web服务器的缓存-Apache或IIS
  • 用户浏览器缓存
  • media.com上的一些文章提到编写服务/指令来通知构建更改。我们还没有实施,但对我来说似乎很有希望


    如果这不能解决问题,请尝试从生成器中清除包缓存。就像我们有基于GitLAb CI的管道也会产生这样的问题一样,为了解决这个问题,我们在GitLAb runner上禁用了源代码/包的缓存。

    我们在本地主机服务器上遇到了同样的问题。原因是chrome和其他浏览器中的证书无效。我们在Chrome中更改了一个选项

    此选项仅适用于通过HTTP向localhost发出的请求


    在Chrome地址栏中,键入并选择“启用”链接。

    LazyModule的默认路由是什么?
    app-routing.module.ts{path:'lazy',loadChildren:'./lazy.module#LazyModule'},通过添加“deployUrl”:“/path”,在.angular-cli.json中的应用程序中,这可能也适用于您:当我更改为“deployUrl”时,它会起作用:“path/”@KirillWarp能否请您详细提供您的问题这对我有效。在我的例子中,这个问题只发生在firefox上,chrome从不在lazyload上显示这个错误