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

NGSW based Service Worker doesn't work in ng8 with differential builds #15259

Closed
elylucas opened this issue Aug 6, 2019 · 9 comments
Closed

Comments

@elylucas
Copy link

elylucas commented Aug 6, 2019

🐞 Bug report

Command (mark with an x)

- [ ] new
- [x] build
- [ ] serve
- [ ] test
- [ ] e2e
- [ ] generate
- [ ] add
- [ ] update
- [ ] lint
- [ ] xi18n
- [ ] run
- [ ] config
- [ ] help
- [ ] version
- [ ] doc

Description

When doing a production build with differential builds (target = es2015 in tsconfig), the service worker does not properly serve up cached esm js files. It throws an error (below in the error section) in the browser console window.

Turning off differential builds (by settings target to es5 in tsconfig) fixes the issue.

Note, this issue only appears to be in Chrome (see the end of the issue).

🔬 Minimal Reproduction

Create a new app:
ng new ng8-pwa-test (I added routing and selected CSS)

Update the bits to make sure on latest:
ng upgrade @angular/cli @angular/core

Add NGSW:
ng add @angular/pwa

Do a prod build:
ng build --prod

Use a local web server to serve up the dist/ng8-pwa-test (using (https://www.npmjs.com/package/local-web-server)[local-web-server myself]):
ws --spa index.html --static.maxage -1 -p 8080 -z -d dist/ng8-pwa-test

Visit http://localhost:8080, open dev tools and verify the service worker is running on the Application tab. Maybe refresh a few times to make sure everything is nice and primed.

Go offline via the Service Worker tab.

Refresh, and get the error down below in the error section.

Now, go into tsconfig.json and turn off differential builds by setting the target to "es5".

Do another prod build:
ng build --prod

Restart the web server:
ws --spa index.html --static.maxage -1 -p 8080 -z -d dist/ng8-pwa-test

Go back to the browser, unregister the existing service worker, clear out any cache, go back online and see the page again.

Now, go back offline, hit refresh, and see the es5 builds are properly being served from the sw cache.

Heres a link to a project already prepped https://github.com/elylucas/ng8-pwa-test

🔥 Exception or Error


ngsw-worker.js:596 Uncaught (in promise) Error: Response not Ok (fetchAndCacheOnce): request for http://localhost:8080/polyfills-es2015.e4a1185e6871d06f842f.js returned response 504 Gateway Timeout
    at PrefetchAssetGroup. (ngsw-worker.js:596)
    at Generator.next ()
    at fulfilled (ngsw-worker.js:320)
(anonymous) @ ngsw-worker.js:596
fulfilled @ ngsw-worker.js:320
localhost/:16 GET http://localhost:8080/main-es2015.a547e075e866b7c26e38.js net::ERR_FAILED
ngsw-worker.js:596 Uncaught (in promise) Error: Response not Ok (fetchAndCacheOnce): request for http://localhost:8080/main-es2015.a547e075e866b7c26e38.js returned response 504 Gateway Timeout
    at PrefetchAssetGroup. (ngsw-worker.js:596)
    at Generator.next ()
    at fulfilled (ngsw-worker.js:320)

🌍 Your Environment



Angular CLI: 8.2.0
Node: 10.15.3
OS: darwin x64
Angular: 8.2.0
... animations, cli, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router, service-worker

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.802.0
@angular-devkit/build-angular     0.802.0
@angular-devkit/build-optimizer   0.802.0
@angular-devkit/build-webpack     0.802.0
@angular-devkit/core              8.2.0
@angular-devkit/schematics        8.2.0
@angular/pwa                      0.802.0
@ngtools/webpack                  8.2.0
@schematics/angular               8.2.0
@schematics/update                0.802.0
rxjs                              6.5.2
typescript                        3.5.3
webpack                           4.38.0

Anything else relevant?
During testing, I noted that this issue only seems to happen in Chrome (in on v76). I tried in Firefox and Safari and they both seemed to work, but the devtools there aren't as good so not sure if I was going offline properly (i just killed the local server).

Therefore, this could be an issue in Chrome and ESM module loading in service workers.

Im also on Mac OSX Mojava.

@alan-agius4
Copy link
Collaborator

alan-agius4 commented Aug 7, 2019

Hi @elylucas, I downloaded your reproduction and tried it locally and I was not able to replicate the exact issue that you are reporting. I am using Chrome version Version 76.0.3809.100 on Windows.

image

That being said, I can see a different error which is for the manifest.webmanifest, which I think we should be adding to the ngsw.json

image

@ngbot ngbot bot added this to the needsTriage milestone Aug 7, 2019
mgechev pushed a commit that referenced this issue Aug 12, 2019
…refetched files in ngws-config.json (#15277)

In the latest versions of Chrome Version 76.0.3809.100, the `manifest.webmanifest` is being requested when offline and is caused a 504 error.

#15259 (comment)
mgechev pushed a commit that referenced this issue Aug 12, 2019
…refetched files in ngws-config.json (#15277)

In the latest versions of Chrome Version 76.0.3809.100, the `manifest.webmanifest` is being requested when offline and is caused a 504 error.

#15259 (comment)
@ahnpnl
Copy link

ahnpnl commented Sep 23, 2019

hi, I have similar issue like @elylucas . However, it randomly happens, sometimes I can reproduce it, sometimes I can't

@CharlyRipp
Copy link

Currently facing this issue as well. Happens consistently between builds.
Produce a production build, load it, let the worker cache.
Produce a new production build, then attempt to load it - will receive the fetchAndCacheOnce method error.

Once you receive this error, refreshing the browser then fetches the latest and everything is happy.
Currently looking at implementing a hack into the ngsw-worker.js to just refresh instead of throwing the error until this is resolved.

@pturner1989
Copy link

Also having this issue on a new project.

@springandangular
Copy link

It seems for me using NPM package http-server instead of NPM package ws to host my Angular 8 production builds resolved the issue in testing.

@hansaliyad1
Copy link

Hello! This issue is still persist in my environment. I will really appreciate if fix is available.

@dgp1130 dgp1130 added needs: investigation Requires some digging to determine if action is needed triage #1 type: bug/fix labels May 27, 2020
@dgp1130 dgp1130 modified the milestones: needsTriage, Backlog May 27, 2020
@ngbot ngbot bot modified the milestones: Backlog, needsTriage May 27, 2020
@dgp1130 dgp1130 modified the milestones: needsTriage, Backlog May 27, 2020
@ngbot ngbot bot modified the milestones: Backlog, needsTriage May 27, 2020
@bhuber2010
Copy link

Just ran into this also... target change to es5 from es2015 seems to have "fixed" it but a real fix would be nice. Also a simple reload after ngsw has download the new files also allows the app to load, which is very strange and seems like ngsw-worker.js has some interaction with Chrome (if this indeed only happens on Chrome, I haven't tested that).

sleidig added a commit to Aam-Digital/ndb-core that referenced this issue Jul 19, 2020
service-workers seem to have a problem no finding the relevant resources on es2015
angular/angular-cli#15259 (comment)
aam-digital-ci pushed a commit to Aam-Digital/ndb-core that referenced this issue Jul 19, 2020
## [2.14.4](2.14.3...2.14.4) (2020-07-19)

### Bug Fixes

* **conflict-resolution:** ensure conflict resolution is done on raw docs rather than entity instance ([3219f21](3219f21))
* **updates:** prevent problems updating to latest version ([b4603c1](b4603c1)), closes [/github.com/angular/angular-cli/issues/15259#issuecomment-635055255](https://github.com//github.com/angular/angular-cli/issues/15259/issues/issuecomment-635055255)
* **webdav:** add way to easily include additional nginx configs for nextcloud forwarding ([298e27a](298e27a))
@alan-agius4
Copy link
Collaborator

This issue is now obsolete since differential loading will be removed in the next major version. See: #21467

@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 3, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

9 participants