2017-05-17 106 views
1

使用角2與延遲裝入模塊,可以接收(例如)從服務器角2.錯誤:裝載塊失敗

bootstrap 0b40fee…:101 GET http://localhost:8082/2.chunk.js

Error: Loading chunk 2 failed. 
at HTMLScriptElement.onScriptComplete (bootstrap 0b40fee…:91) 
at HTMLScriptElement.wrapFn (zone.js:1032) 
at ZoneDelegate.invokeTask (zone.js:414) 
at Object.onInvokeTask (core.es5.js:4119) 
at ZoneDelegate.invokeTask (zone.js:413) 
at Zone.runTask (zone.js:181) 
at HTMLScriptElement.ZoneTask.invoke (zone.js:476) 

如何處理該錯誤401 HTTP代碼?

+0

你如何爲你的應用程序?用ng服務還是stg其他?這種問題可能與錯誤的路徑有關,你能否提供更多的細節? – ulubeyn

+0

路徑很好。問題是如何處理加載塊(webpack)錯誤。原因可以是任何HTTP錯誤代碼 – smie

回答

-2

這不像你的意見像任何HTTP錯誤,我曾經面臨這個問題。它只是基於您的瀏覽器。可能有兩個原因。他們是

  1. You have to install the latest version of browser.

如果你的瀏覽器,如果不能夠讀取這些文件。它會造成這個錯誤。

  1. Just try to avoid other process on that time.

因爲您的瀏覽器需要專注於該進程並且必須讀取所有文件。如果瀏覽器沒有讀取文件,那會產生這個錯誤。

So you have to reduce the process and reload the page.It will run perfectly.

謝謝。

-1

這可能意味着未處理的異常。您必須以任何您想要的方式處理來自服務器的錯誤響應(4xx,5xx狀態碼):在某處顯示錯誤消息,重定向到某個頁面,執行任何操作,但不會處理它。

例如:

return this.http.get(requestDetails) 
      .map(res => res.json()) 
      .catch(err => { 
console.log('server error:', err) 
Observable.throw(err); 
}); 
0

我有同樣的問題,所以我調查。我找到了解決方案。當我重新部署到另一臺服務器並且該塊有[hash]時,這發生在我身上。

您可以捕獲錯誤或者在包羅萬象的是這樣的:

ngOnInit() { 
    if (!this.previousRouterErrorHandler) { 
     this.previousRouterErrorHandler = this.router.errorHandler; 
     let that = this; 
     this.router.errorHandler = function (err: any) { 
      // Handle here. err.message == "Loading chunk chunk-name failed." 

      return that.previousRouterErrorHandler.apply(that.previousRouterErrorHandler, arguments); 
     }; 
    } 
} 
在其導航鏈接

或者直接

click() { 
    this.router.navigate(['/lazy-route']) 
     .catch(err => { 
      // Handle here 
     }); 
}