Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ng build --watch does not generate ngsw pwa workers. #16883

Closed
1 of 15 tasks
axos88 opened this issue Feb 7, 2020 · 6 comments · Fixed by #18463
Closed
1 of 15 tasks

ng build --watch does not generate ngsw pwa workers. #16883

axos88 opened this issue Feb 7, 2020 · 6 comments · Fixed by #18463

Comments

@axos88
Copy link

axos88 commented Feb 7, 2020

🐞 Bug report

ng build --watch does not generate ngsw-worker.js, and siblings.

Command (mark with an x)

  • new
  • build
  • serve
  • test
  • e2e
  • generate
  • add
  • update
  • lint
  • xi18n
  • run
  • config
  • help
  • version
  • doc

Is this a regression?

Not sure. Had the same problem with angular 8, figured out it was the watch flag only after i upgraded to 9.

Description

ng build --watch --prod: no ngsw-worker & siblings under dist/project
ng build --watch --prod: ngsw-worker & siblings are generated under dist/project

🔬 Minimal Reproduction

new new foo
cd foo
ng add @angular/pwa
ng build --watch --prod

🌍 Your Environment


     _                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/
    

Angular CLI: 9.0.1
Node: 10.17.0
OS: linux x64

Angular: 9.0.0
... animations, common, compiler, compiler-cli, core, forms
... language-service, localize, platform-browser
... platform-browser-dynamic, router, service-worker
Ivy Workspace: Yes

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.900.1
@angular-devkit/build-angular     0.900.1
@angular-devkit/build-optimizer   0.900.1
@angular-devkit/build-webpack     0.900.1
@angular-devkit/core              9.0.1
@angular-devkit/schematics        9.0.1
@angular/cli                      9.0.1
@ngtools/webpack                  9.0.1
@schematics/angular               9.0.1
@schematics/update                0.900.1
rxjs                              6.5.4
typescript                        3.7.5
webpack                           4.41.2


@alan-agius4
Copy link
Collaborator

This is actually by design. Maybe @clydin would know the exactly details why under watch these are not generated though.

@axos88
Copy link
Author

axos88 commented Feb 8, 2020

Well, I just pulled my remaining hairs out by design then...

At least a warning and an option to turn this off would be great, because I am usually working with ng build --watch running in the background, and spent hours trying to figure out why they don't get generated

@axos88 axos88 changed the title ng buiild --watch does not generate pwa workers. ng build --watch does not generate pwa workers. Feb 8, 2020
@axos88 axos88 changed the title ng build --watch does not generate pwa workers. ng build --watch does not generate ngsw pwa workers. Feb 8, 2020
@ngbot ngbot bot modified the milestone: Backlog Feb 8, 2020
@kyliau kyliau added area: angular/pwa triage #1 needs: discussion On the agenda for team meeting to determine next steps labels May 29, 2020
@dgp1130
Copy link
Collaborator

dgp1130 commented Jun 11, 2020

Talked with @clydin today and it seems that ng build --watch currently does not build service workers because ng serve does not build service workers because we don't currently have a good means of running a PWA locally (there are a few requirements, such as SSL, that are hard to satisfy locally).

As a result, this seems to be mostly an oversight. We don't see any reason ng build --watch shouldn't build a service worker, it's only ng serve where that doesn't work out. In fact, applications may want to use ng build --watch and then serve it with a custom stack to manually fulfill those PWA requirements.

Most likely somewhere in the CLI we are checking if (!buildOptions.watch) { buildServiceWorker(); } when we should be doing if (buildCommand !== 'serve') { buildServiceWorker(); }.

This is just a bug we'll need to look into more.

@axos88
Copy link
Author

axos88 commented Jun 26, 2020

https://stackoverflow.com/a/34161385
"There's an exception to the HTTPS requirement in place to facilitate local development: if you access your page and service worker script via http://localhost[:port], or via http://127.x.y.z[:port], then service workers should be enabled without any further actions."

So serving a PWA locally shouldn't be a problem anymore, and also there may be more complicated setups where there is a valid certificate in place, for example I am using ng serve to serve PWA locally. I have an SSL certificate for a domain I own, and set up port forwarding for that host to my locally served application. I am using this for development only of course, and would benefit from ng serve --watch building the PWA files to be served.

@dgp1130
Copy link
Collaborator

dgp1130 commented Jun 26, 2020

Should also look into ng serve building the service worker as well as ng build --watch per #10483.

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 6, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants