Failed to register a ServiceWorker

Hello, I’m struggling with the following error for some time:
TypeError: Failed to register a ServiceWorker for scope (‘http://localhost/’) with script (‘http://localhost/sw.js’): An unknown error occurred when fetching the script.

The actual code:

Basically I took the PWA example from here:
Then followed the instructions for capacitor here:

In the browser runs fine, service worker registers ok.
However, when running in Android (npx cap sync && npx cap open android), in an Emulator, i get the error above.

What is the issue here? Thank you in advance. If any additional details needed, please let me know.

1 Like

Hey, I am facing the same issue. Is the issue solved on your end ?