0

I started new Angular 8 project with those specs:

Angular CLI: 8.0.4
Node: 10.16.0
OS: darwin x64
Angular: 8.0.2

Angular PWA:

ng add @angular/pwa

package.json

  "dependencies": {
    "@angular/animations": "~8.0.1",
    "@angular/common": "~8.0.1",
    "@angular/compiler": "~8.0.1",
    "@angular/core": "~8.0.1",
    "@angular/forms": "~8.0.1",
    "@angular/platform-browser": "~8.0.1",
    "@angular/platform-browser-dynamic": "~8.0.1",
    "@angular/pwa": "^0.800.4",
    "@angular/router": "~8.0.1",
    "@angular/service-worker": "~8.0.1",
    "rxjs": "~6.4.0",
    "tslib": "^1.9.0",
    "zone.js": "~0.9.1"
  },

I have 2 error in console on startup. How can I fix it?

A bad HTTP response code (404) was received when fetching the script. service-worker.js.pre-build-optimizer.js:451

Service worker registration failed with: TypeError: Failed to register a ServiceWorker: A bad HTTP response code (404) was received when fetching the script.

Community
  • 1
  • 1
Mike Kylmä Lampi
  • 465
  • 1
  • 5
  • 15

1 Answers1

1

If you are trying to test this locally with the CLI, the service worker will throw this error. You need to test following these instructions.

Further, if not on localhost, browsers reject service workers over insecure connections (http vs https) see here.

dockleryxk
  • 407
  • 2
  • 11
  • Actually, no. With localhost everything should be fine ( "There is one exception to this rule: To make local development easier, browsers do not require a secure connection when accessing an app on localhost." - https://angular.io/guide/service-worker-intro ). I tried before version 7, and there were no errors. Did you personaly tried version 8? – Mike Kylmä Lampi Jun 25 '19 at 20:13
  • I mean locally explicitly with the CLI (ng serve). You need to serve it locally with something different to test. In those instructions I linked, they use the http-server package. I have a service worker in different projects with 7 as well as 8. If this is what you are doing, please update your post with your configuration and how you are registering in your module. – dockleryxk Jun 25 '19 at 20:42
  • My confs are default - nothing more than mentioned in the description above. The project was created with "ng new ProjectName". Now I uploaded this app to the firebase server (it has https), there are no errors, but the app, like before, for example, doesnt show me the pop-up message - "Add ProjectName to Home screen". Its even impossible to choose something similar in the Chrome´s menu from the right upper corner. – Mike Kylmä Lampi Jun 25 '19 at 21:39
  • Are you checking on iOS? It won't work there. Also, firebase might have some caveats. A cursory search brought up many articles on angular service workers on firebase – dockleryxk Jun 26 '19 at 14:51
  • I changed a version to a 8.0.2 and its fine ..Works on Mac, and on Firebase as well. Thanks for your help! – Mike Kylmä Lampi Jun 26 '19 at 14:56
  • I am glad you figured it out. Service workers are extremely frustrating! – dockleryxk Jun 26 '19 at 15:02