We have implemented PWA (@angular/service-worker) and in prod mode everything works as expected. We are using angular universal. But in dev mode, the file "ngsw-worker.js" is not generated.
I already changed the registration to enabled on all environments:
ServiceWorkerModule.register('./ngsw-worker.js', {
enabled: true,
})
And of course it's added in angular.json:
"projects": {
"client-app": {
...
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"serviceWorker": true,
"ngswConfigPath": "ngsw-config.json"
}
But the file is still not generated, I cannot find any reference to this file in the code. We use "npm run dev:ssr" which is part of the angular universal template to run the app in development environment. My guess is that the serviceworker is not built with this command.
The browser shows this message since it cannot find this file and is trying to read the index file which it's redirected to:
home-routing.module.ts:19 Service worker registration failed with: DOMException: Failed to register a ServiceWorker for scope ('http://localhost:4200/') with script ('http://localhost:4200/ngsw-worker.js'): The script has an unsupported MIME type ('text/html').
We need to be able to test PWA features during development as well.
How can we add this file in dev build?