nx: ng add @angular/pwa fails to find ngsw-config.json on angular cli to nx workspace

ng new morningharwood --routing
ng generate universal --client-project morningharwood
ng generate app-shell --universal-project  --route=app-shell-path --client-project=morningharwood
ng add @angular/pwa --project morningharwood
ng build --prod
cd dist/morningharwood
http-server

Open up inspector go to appication tab and you’ll see the service working working as intended.

Ok now lets convert to nx

ng add @nrwl/schematics --project morningharwood
npm install --save rxjs-compat 
ng build --prod

ng build --prod will fail and throw this error:

Error: Expected to find an ngsw-config.json configuration file in the /Users/mharwo/workspace/www/test/morningharwood/apps/morningharwood folder. Either provide one or disable Service Worker in your angular.json configuration file.
Error: Error: Expected to find an ngsw-config.json configuration file in the /Users/mharwo/workspace/www/test/morningharwood/apps/morningharwood folder. Either provide one or disable Service Worker in your angular.json configuration file.
    at SwitchMapSubscriber.host.exists.pipe.operators_1.switchMap.exists [as project] (/Users/mharwo/workspace/www/test/morningharwood/node_modules/@angular-devkit/build-angular/src/angular-cli-files/utilities/service-worker/index.js:91:19)
    at SwitchMapSubscriber._next (/Users/mharwo/workspace/www/test/morningharwood/node_modules/rxjs/internal/operators/switchMap.js:90:27)
    at SwitchMapSubscriber.Subscriber.next (/Users/mharwo/workspace/www/test/morningharwood/node_modules/rxjs/internal/Subscriber.js:103:18)
    at Observable.rxjs_1.Observable.obs [as _subscribe] (/Users/mharwo/workspace/www/test/morningharwood/node_modules/@angular-devkit/core/node/host.js:207:17)
    at Observable._trySubscribe (/Users/mharwo/workspace/www/test/morningharwood/node_modules/rxjs/internal/Observable.js:177:25)
    at Observable.subscribe (/Users/mharwo/workspace/www/test/morningharwood/node_modules/rxjs/internal/Observable.js:162:93)
    at SwitchMapOperator.call (/Users/mharwo/workspace/www/test/morningharwood/node_modules/rxjs/internal/operators/switchMap.js:69:23)
    at Observable.subscribe (/Users/mharwo/workspace/www/test/morningharwood/node_modules/rxjs/internal/Observable.js:159:22)
    at MapOperator.call (/Users/mharwo/workspace/www/test/morningharwood/node_modules/rxjs/internal/operators/map.js:62:23)
    at Observable.subscribe (/Users/mharwo/workspace/www/test/morningharwood/node_modules/rxjs/internal/Observable.js:159:22)
    at SwitchMapOperator.call (/Users/mharwo/workspace/www/test/morningharwood/node_modules/rxjs/internal/operators/switchMap.js:69:23)
    at Observable.subscribe (/Users/mharwo/workspace/www/test/morningharwood/node_modules/rxjs/internal/Observable.js:159:22)
    at SwitchMapOperator.call (/Users/mharwo/workspace/www/test/morningharwood/node_modules/rxjs/internal/operators/switchMap.js:69:23)
    at Observable.subscribe (/Users/mharwo/workspace/www/test/morningharwood/node_modules/rxjs/internal/Observable.js:159:22)
    at SwitchMapOperator.call (/Users/mharwo/workspace/www/test/morningharwood/node_modules/rxjs/internal/operators/switchMap.js:69:23)
    at Observable.subscribe (/Users/mharwo/workspace/www/test/morningharwood/node_modules/rxjs/internal/Observable.js:159:22)

I would guess the project doesnt transfer the ngsw-config.json

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 4
  • Comments: 16 (5 by maintainers)

Most upvoted comments

I checked the NX branch of your repo. Your ngsw-config.json is in the wrong directory. Instead of in the root, it should be in apps/morningharwood, as it is app specific.

@vsavkin with the advent of the Angular Console this is no longer an issue for me as it simplifies a lot things and in general a visual experience makes it really easy to use. Thanks.

I tried this a similar setup only however i was already inside an nx-workspace from using @nrwl/schematics nothing service-worker related was created example:

CREATE ngsw-config.json (392 bytes)
CREATE src/assets/icons/icon-128x128.png (1253 bytes)
CREATE src/assets/icons/icon-144x144.png (1394 bytes)
CREATE src/assets/icons/icon-152x152.png (1427 bytes)
CREATE src/assets/icons/icon-192x192.png (1790 bytes)
CREATE src/assets/icons/icon-384x384.png (3557 bytes)
CREATE src/assets/icons/icon-512x512.png (5008 bytes)
CREATE src/assets/icons/icon-72x72.png (792 bytes)

So on inside my existing nx-workspace i did ng g app my-pwa-app --service-worker No service-worker files were created ng g app my-pwa-app => ng add @angular/pwa --project my-pwa-app This added the service-worker dependency inside my package.json however thats all it did.

@michelcve ahh I feel so stupid … thanks! It works now.
@Yonet I guess we should close this.

Side question for anyone: Are there any discussions on how to reconcile two or more schematics, like ng add @angular/pwa and ng add @nrwl/schematics. Esp with more to come like ngrx and universal. Seems pretty hard to solve without manual efforts (like this one) or authors collaborating.