Should be able to register service worker for an Angular app.
There are 2 things I observed:
ngsw-worker.js in dist/apps/<app_name>ngsw-worker.js), therefore service worker for app doesn't work.I tested with 2 ways of generating an Nx workspace, either with Nx CLI or Angular CLI, both resolved in the same behaviors like described ones above.
Please provide detailed steps for reproducing the issue.
yarn.nx build.yarn sworker.ngsw-worker.js isn't loaded.dist/apps/myapp and observe that ngsw-worker.js isn't there.Please provide any relevant information about your setup:
Example repo at: https://github.com/ahnpnl/nx-sw-bug
N.A.
@angular/pwa was installed with version 0.802.2, I see the version is different from @angular-devkit/build-angular. So I tried to install @angular/pwa with the same version as @angular-devkit/build-angular but this didn't help either.@ahnpnl @vsavkin I cannot reproduce this issue.
I created a new workspace with npx --ignore-existing create-nx-workspace myworkspace-test-service-worker and select angular as preset.
After that I installed the pwa related packages. ng add @angular/pwa --project=testing-pwa and then run ng build testing-pwa --configuration production
Looking inside the dist folder of my app, I can the see the ngsw-worker.js has beed created, along with some other files.
Would you please try it again @ahnpnl ? If you like, I can upload my workspace where I tested it.
this only happens if choosing Nx CLI when generating a workspace. If choosing Angular CLI when generating a workspace, it works fine.
Please refer to your own issue https://github.com/nrwl/nx/issues/1730
The reason why it won't work, is that NX is NOT a copy of NG in some sort.
For the time being, please only use NX for react and web-components. If you need Angular related packages, please use the NG CLI.
hi @mehrad-rafigh , I wonder nrwl has any tools to switch a workspace generated by Nx CLI to a workspace generated by Angular CLI ? That would be convenient and more flexible for users.
Hey folks!
Nx CLI doesn't support the add command. But if you look at the changes made by ng add @angular/pwa --project=testing-pwa and apply those manually to your Nx CLI workspace, the pwa stuff should work.
If you want to change your workspace to use the Angular CLI, you can do it by:
@angular/cli to package.jsonworkspace.json into angular.jsonAnd you should be good to go.
@ahnpnl We don't provide any tools to move from the standalone version of Nx to the Angular CLI one at the moment. I think going in the other direction is probably more common, where you start with Angular and then want to go to a framework-agnostic setup, so you can add React and Node. Currently, you have to manually rename the config file and patch package.json.
Thank you! I will try that.
Folks. I'm going to close this issue.
If the pwa package doesn't work in an Angular-CLI-powered Nx workspace, please reopen it. And we will take a look.
Folks. I'm going to close this issue.
If the pwa package doesn't work in an Angular-CLI-powered Nx workspace, please reopen it. And we will take a look.
Hi just leaving this for anyone who may run into this issue as well, for me I had to remove sideEffects: false from package.json.
Most helpful comment
Hey folks!
Nx CLI doesn't support the
addcommand. But if you look at the changes made byng add @angular/pwa --project=testing-pwaand apply those manually to your Nx CLI workspace, the pwa stuff should work.If you want to change your workspace to use the Angular CLI, you can do it by:
@angular/clitopackage.jsonworkspace.jsonintoangular.jsonAnd you should be good to go.
@ahnpnl We don't provide any tools to move from the standalone version of Nx to the Angular CLI one at the moment. I think going in the other direction is probably more common, where you start with Angular and then want to go to a framework-agnostic setup, so you can add React and Node. Currently, you have to manually rename the config file and patch
package.json.