question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Chunk loading errors when using SW + lazy loaded modules

See original GitHub issue

🐞 bug report

Affected Package

Angular 11.x

Is this a regression?

I think so, never observed the issue with Angular 10

Description

We use Service Workers and lazy loaded modules in our application. What happens is that very often now, we get the “chunkLoadingError” when one version of the PWA is trying to fetch a lazy loaded module for a previous version.

So: deploy version A Make changes, deploy as version B

Close the browser, wait 10 mins, load the application again. When the application tries to load a chunk from the previous deployment A, it fails because naturally this chunk does not exist any longer.

We are of course using the Service Worker service swUpdate to get notifications when a new version is available. However, it seems sometimes not all lazy loaded chunks are updated when there is a new SW version.

We are using Ngrx/Store to subscribe and listen to the swUpdate service observables: available and the new unrecoverable :

 // Listen for new versions of application available
  newVersion$ = createEffect( () => this.swUpdate.available.pipe(
      map( () => this.swUpdate.activateUpdate()),
      switchMap( () => of(navigateAction([ '/', {outlets: { dialog: 'new-version' } } ])))
  ));

   // Listen for unrecoverable state from the service worker
   swUnrecoverable$ = createEffect( () => this.swUpdate.unrecoverable.pipe(
     map( event => {
       console.log('Service worker unrecoverable event, reloading application');
       window.location.reload();
     })
   ), { dispatch: false });

The problem is that it seems like doesn’t seem swUpdate.unrecoverable subscription is ever triggered. Maybe it’s a bug? Or am I doing something wrong? Thanks

🌍 Your Environment

Angular Version:


Angular: 11.0.3
... animations, cli, common, compiler, compiler-cli, core, forms
... language-service, localize, platform-browser
... platform-browser-dynamic, platform-server, router
... service-worker
Ivy Workspace: Yes

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.901.7
@angular-devkit/build-angular   0.1100.3
@angular-devkit/core            9.1.7
@angular-devkit/schematics      11.0.3
@angular/cdk                    11.0.1
@angular/fire                   6.1.2
@angular/material               11.0.1
@nguniversal/builders           9.1.1
@nguniversal/express-engine     9.1.1
@schematics/angular             11.0.3
@schematics/update              0.1100.3
rxjs                            6.5.5
typescript                      4.0.5

Maybe important?

We use i18n to deploy 7 different versions of the application, each with its own service worker

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
gkalpakcommented, Dec 13, 2020

Thx for reporting this, @spock123!

However, I am afraid the provided info doesn’t give use much to work with. The behavior you see could have many root causes, including:

  • Incorrect SW configuration.
  • Automatic server/proxy optiimization.
  • Angular SW bug.

It would be best if you could provide a minimal reproduction. If that is not possible, then you could provide more information about your app and the behavior you see (for example, the SW config (both ngsw-config.json and the generated ngsw.json), exact error message in the console, the output of ngsw/state, etc.).

Other things that would help diagnose the problem would be a publicly available deployed version of the app and instrumenting the SW script to gather more info, such as the contents of the caches when the error occurs.

0reactions
angular-automatic-lock-bot[bot]commented, Jan 13, 2021

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Loading chunk failed issue angular | fieldcircle
When we deploy a new version of an app, we often encounter with loading chunks failed issue. It happens because the new version...
Read more >
How to Solve the Chunk Load Error in JavaScript
Whenever there's an error observed in dynamically fetching helper JavaScript files known as Chunks, a ChunkLoad Error is thrown.
Read more >
How to overcome loading chunk failed with Angular lazy ...
You use global error handling and force app to reload if chunks failed. import {ErrorHandler, Injectable} from '@angular/core'; ...
Read more >
Angular 11: A Complete Guide to Lazy Loading
Lazy loading in Angular 11 improves the performance and speed of an application. But how is it implemented? This guide explains everything you...
Read more >
Dealing with Code Splitting Network Failures
I refresh the page and try again. This same principle can be applied to code split chunks. If there is a failure, load...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found