1

Chrome Manifest tab:

enter image description here

I don't see any service worker either, Chrome Service Worker tab:

enter image description here

Here is my manifest.json:

{
    "short_name": "shortname",
    "name": "Full Name",
    "icons": [
      {
        "src": "img/logo.svg",
        "type": "image/svg",
        "sizes": "512x512"
      }
    ],
    "start_url": "/",
    "background_color": "#cc2366",
    "display": "standalone",
    "scope": "/",
    "theme_color": "#cc2366"
}

app.module.ts

...
import { ServiceWorkerModule } from '@angular/service-worker';
import { AppComponent } from './app.component';
import { environment } from '../environments/environment';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    ...
    environment.production ? ServiceWorkerModule.register('/ngsw-worker.js') : [],
    ...
  ],
  providers: [
  ],
  bootstrap: [
    AppComponent
  ]
})
export class AppModule {
}

.angular-cli.json

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "project": {
    ...
  },
  "apps": [
    {
      ...
      "serviceWorker": true,
      ...
    }
  ],
  "e2e": {
    ...
  },
  "lint": [
    ...
  ],
  "test": {
    ...
  },
  "defaults": {
    ...
  }
}

However I am able to access https://myrooturl/ngsw-worker.js via browser.

What am I missing?

(disc: some non relevant codes are shown dotted )

ishandutta2007
  • 16,676
  • 16
  • 93
  • 129

1 Answers1

0

Your syntax is wrong. It should be.

  imports: [
    ...
    ServiceWorkerModule.register('ngsw-worker.js', { enabled: environment.production }) : [],
    ...
  ],
denov
  • 11,180
  • 2
  • 27
  • 43
  • thats not the issue, I posted the error from production – ishandutta2007 Apr 19 '19 at 06:00
  • is angular adding the 'navigator.serviceWorker.register' to your source? – denov Apr 19 '19 at 21:55
  • actually that way of writing was wrong, enabling production should be argument, this fixed it https://stackoverflow.com/a/54996593/865220 – ishandutta2007 Apr 22 '19 at 06:39
  • that's great you found the answer! i changed my answer to be correct for next peoples that come across this. – denov Apr 22 '19 at 16:06
  • But now I am stuck with a different issue, maybe you can take a look https://stackoverflow.com/questions/55797611/swupdate-isenabled-is-true-but-not-calling-the-subscribed-method-even-when-ngsw – ishandutta2007 Apr 22 '19 at 16:49