Ionic/Angular/Capacitor - Service worker registration failed

Viewed 1889

I have a problem with ServiceWorker in Ionic 5 (Angular+Capacitor) app. I have added the service worker to my app by

ng add @angular/pwa

After I build it ionic build --prod, go to www directory and use http-server -p 8080 everything is fine and service worker is working.

After that I use npx cap copy and I am building app on my device by using Android Studio. And in this case I can see an error:

main-es2015.b31a6be113e928f57737.js:1 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.
0 Answers
Related