Skip to content

Angular builds with @angular/service-worker creates incorrect hashes #119

Description

@hpieterse

Description

With an Angular project using @ngx-env/builder:

  • when using @angular/service-worker to add service worker support, and
  • replacing something in the index.html from an environment variable,
  • a build generated a ngsw.json file with incorrect hashes.

Example

Here is an minimal example
https://stackblitz.com/edit/ngx-env-dht6lfds

To reproduce the issue:

  1. run npm run build

  2. check the hash of the index.html file using:

shasum ./dist/demo/browser/index.html

(this command is not available in StackBlitz, so you will have to download the file locally)

  1. Compare this to the hash in dist/demo/browser/ngsw.json

Cause

This was probably introduced in this PR #108. in packages/angular/src/builders/browser/index.ts the index.html file is changed after the build, which is probably after the service worker hashes where generated.

Workaround

As a workaround (if someone with the same problem happens finds this issue) you can re-calculate the hashes using something like this:

npx ngsw-config dist/demo/browser/ ngsw-config.json

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions