Skip to content Skip to sidebar Skip to footer

Webpack - Loading Chunk 0 Failed

Some of my users are getting this error: Unhandled rejection message: 'Loading chunk 0 failed' stack: Loading chunk 0 failed at HTMLScriptElement.n The problem is, I've no succ

Solution 1:

The reason for this is because I used require.ensure with webpack which creates chunks and using jsonp to add this script on demand, in other words, It's adding script src tag to the html with the created chunk file.

It seems that some users have extensions or even some configuration to block such jsonp requests regardless whether it's the same domain or not.

One solution is not using require.ensure at all obviously, or using the error callback to handle this scenario.

In addition was looking for a way that webpack will load the script using xhr + eval, which will prevent such scenarios. I just found this npm module: https://github.com/elliottsj/xhr-eval-chunk-webpack-plugin, yet I expected it to be more supported by webpack itself.

I've opened an issue for this : https://github.com/webpack/webpack/issues/5630, hopefully to see some progress.


Solution 2:

Answer for search from google:

In my case Error: Loading chunk 9 failed. fired only in Firefox. Caused by positive lookbehind regexp. (?<=...)

Note that this feature is not yet supported on all browsers; use at your own discretion!


Solution 3:

The problem can be caused by:

  • Unstable internet connection
  • Wrong/malformed browser cache

The only solution I found is retry the chunk load with this Webpack plugin: https://github.com/mattlewis92/webpack-retry-chunk-load-plugin

It will:

  • Retry loading the chunk once a second.
  • Will add ?cache-bust=X query to avoid (probably malformed) cached JS file.

The downside is - it reties indefinitely.


Solution 4:

Just check for path which going to load your chunks file(js files). Check path of deployURL in angular.json file.

"build": {
    "builder": "@angular-devkit/build-angular:browser",
    "options": {
      "outputPath": "./Scripts/app",
      "deployUrl": "./Scripts/app/",
      "index": "app/index.html",
      "main": "app/main.ts",
      "polyfills": "app/polyfills.ts",
      "tsConfig": "tsconfig.app.json",
      "aot": false,
      "assets": [
        "app/favicon.ico",
        "app/assets"
      ],

Solution 5:

If you are on Cloudflare, or any CDN host for your web server, try purging the cache as this may be caused by caches from the old version of your app. It fails as the new build does not correspond to the old one.


Post a Comment for "Webpack - Loading Chunk 0 Failed"