6

I have a problem with @angular/pwa. when I am building in production mode I am not getting ngsw-worker.js and ngsw.json files in my dist folder.

the pwa version am using is:

@angular/pwa: ^0.13.8
@angular/service-worker: ~7.1.0
@angular version 7

Thanks in advance

Jake Neumann
  • 372
  • 4
  • 13
VinoPravin
  • 947
  • 3
  • 17
  • 32

2 Answers2

-1

This answer is only relevant when:

nx version 11

Now the workaround for version 10 (see below) does not work anymore!

a workaround can be to opt-out of the nx ng-cli-decorate patch

quote from nx#4452:

To opt out of this patch:

Replace occurrences of nx with ng in your package.json Remove the script from your postinstall script in your package.json Delete and reinstall your node_modules

nx version 10

To fix the issue (we use nx version 10) we replaced:

  • ng build client --configuration=production,variant with
  • nx build client -c=production,variant

The problem was, that nx did not pass the configuration correctly to ng and thus ng did not build the production configuration (thus no PWA/service-worker)

Links to nx issues:

TmTron
  • 17,012
  • 10
  • 94
  • 142
-2

You can copy the files from the node_modules folder (from a prompt in your project folder):

cp node_modules/@angular/service-worker/ngsw-worker.js ./src/ngsw-worker.js
cp node_modules/@angular/service-worker/ngsw-config.json ./ngsw-config.json

You may also need to make sure your service worker is registered. Nice presentation on the subject at: https://javascript-conference.com/wp-content/uploads/2017/12/Automatic_Progressive_Web_Apps_using_Angular_Service_Worker_Maxim_Salnikov.pdf