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)
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-workspacefrom using@nrwl/schematicsnothing service-worker related was created example:So on inside my existing
nx-workspacei didng g app my-pwa-app --service-workerNo service-worker files were createdng g app my-pwa-app=>ng add @angular/pwa --project my-pwa-appThis added the service-worker dependency inside mypackage.jsonhowever 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/pwaandng 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.