3

Creating Angular (8.2.14 Core, 8.2.14 Compiler) production builds with output-hashing enabled by default:

ng build --prod

In the dist folder files are output with hashes, for example:

runtime-es2015.3e680dc09930fcde0e9e.js

When I deploy a new production build and reload my Angular application, I get the following error:

ngsw-worker.js:596 Uncaught (in promise) Error: Response not Ok (fetchAndCacheOnce): request for HOST_URL/runtime-es2015.e7cba659031e36694bf2.js returned response 404 Not Found
    at PrefetchAssetGroup.<anonymous> (ngsw-worker.js:596)
    at Generator.next (<anonymous>)
    at fulfilled (ngsw-worker.js:320)

This is because the output hash for the runtime file has changed between production builds and the service worker can no longer find the file. This happens with multiple files.

This prevents my application from reloading. You have to clear the cache for the application to start working again.

How do I resolve this issue? Shouldn't service worker fail gracefully if it can not find the file and allow the page to reload?

Here is my ngsw-config.json file:

{
  "$schema": "./node_modules/@angular/service-worker/config/schema.json",
  "index": "/index.html",
  "start_url": "/index.html",
  "assetGroups": [
    {
      "name": "app",
      "installMode": "prefetch",
      "resources": {
        "files": [
          "/favicon.ico",
          "/index.html",
          "/manifest.webmanifest",
          "/*.css",
          "/*.js"
        ]
      }
    }, {
      "name": "assets",
      "installMode": "lazy",
      "updateMode": "prefetch",
      "resources": {
        "files": [
          "/assets/**",
          "/*.(eot|svg|cur|jpg|png|webp|gif|otf|ttf|woff|woff2|ani)"
        ]
      }
    }
  ]
}

3 Answers 3

1

change your manifest.webmanifest file to manifest.json and where it is used (angular.json, index.html and ngsw-config.json)

Sign up to request clarification or add additional context in comments.

2 Comments

Can you explain this a bit more? Does it come from an older version?
I don't know why angular generate a .webmanifest file instead of json. When you build the app, it will search for manifest.json. Also, to be found, you need to build your package from root location (where package.json and angular.json are located)
0

Answering my own question, using the NPM package ws to serve the production build seems to be the issue.

Could not reproduce the issue when using NPM package http-server to serve the production build for testing.

Comments

0

I resolved the issue by running the following commands

  1. npm install -g @angular/cli@latest
  2. npm uninstall @angular-devkit/build-angular
  3. npm install --save-dev @angular-devkit/build-angular
  4. Delete node modules folder.
  5. npm install

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.