Service worker registration failed with: TypeError: Failed to register a ServiceWorker for scope ('http://localhost/') with script ('http://localhost/ngsw-worker.js'): An unknown error occurred when fetching the script

I’ve added @angular/pwa and it’s working fine in web. But when i install apk in android and open app the console have error “Service worker registration failed with: TypeError: Failed to register a ServiceWorker for scope (‘http://localhost/’) with script (‘http://localhost/ngsw-worker.js’): An unknown error occurred when fetching the script.”

Can you help what is the issue?

Here is my configuration:
Ionic:

Ionic CLI : 6.19.0
Ionic Framework : @ionic/angular 6.1.6
@angular-devkit/build-angular : 13.2.6
@angular-devkit/schematics : 13.2.6
@angular/cli : 13.2.6
@ionic/angular-toolkit : 6.1.0

Capacitor:

Capacitor CLI : 3.5.1
@capacitor/android : 3.5.1
@capacitor/core : 3.5.1
@capacitor/ios : not installed

Utility:

cordova-res : 0.15.4
native-run : 1.6.0

System:

NodeJS : v14.17.2
npm : 8.3.1
OS : Windows 10

1 Like

It’s happening to me too