0

Within an Angular project the following commands were run using the command line:

ng add @angular/pwa  
ng build --prod

The output in the /dist folder was published as a static website.
https://azureadb2ctesting1.z9.web.core.windows.net/

When running the URL through PWABuilder, the manifest is detected, but not the service worker. Also when changing the networking in Chrome devtools to offline, the page does not load normally, but displays "There is no Internet connection" instead.

Also notice the following error in the console:

main.cb0300ed077227f6fc7f.js:1 Service worker registration failed with: DOMException: Failed to register a ServiceWorker for scope ('https://azureadb2ctesting1.z9.web.core.windows.net/') with script ('https://azureadb2ctesting1.z9.web.core.windows.net/ngsw-worker.js'): The script has an unsupported MIME type ('text/plain').

How can the service worker be enabled for this Angular PWA?

1 Answer 1

0

In angular.json you should have : "serviceWorker": true

In your application root module you should have the following line in the import :

ServiceWorkerModule.register('/ngsw-worker.js', { enabled: environment.production })
Sign up to request clarification or add additional context in comments.

8 Comments

Those are both there. Looks like they were automatically generated when running the command line installation.
But that issue is not output to the console in dev tools. There is another error output about unsupported MIME type ('text/plain'). See the developer console in the example link, also added the error into the question above.
It looks like a problem with hosting and serving rather than a problem with Angular. Your link is not valid, how did you build your project and how do you serve it ?
azureadb2ctesting1.z9.web.core.windows.net is the link to the example. Built using the command ng build --prod. Files moved into Azure Storage container configured as a static website.
Are you sure all your url are set to use https ?
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.