I've followed the official guide of angular and successfully installed the initial service worker. Next I wanted to tryout the updating behaviour and got a
TypeError: Cannot read property 'id' of undefined
where as id refers to client.id in a method in ngsw-worker.js
async updateClient(client) {
// Figure out which version the client is on. If it's not on the latest,
// it needs to be moved.
const existing = this.clientVersionMap.get(client.id);
....
}
The steps i did are
I'm using angular-cli 1.7.4 and all angular libraries including service-worker are on 5.2.10.
Edit 1 08.05.2018
There is an issue posted on github on angular-cli 6 https://github.com/angular/angular/issues/23742
Edit 2 08.05.2018
What I could find out so far:
ng build --prod does not create a new version of ngsw-worker.js (on reloading the new fresh build, chrome does not display the "wait for activation"). When I reload with or without closing the tab prior, the error appears.
When I manually add something to ngsw-worker.js (like a console.log) then the usually lifecycle starts and the old service worker is being replace by the "new" one.
When I reload before the activation is being done, the same error appears. Otherwise it works...
Furthermore trying to remove the service-worker using angular's Fail-safe (removing or renaming the ngsw-config) causes a build error.
Expected to find an ngsw-config.json configuration file in the /Users/hanche/Desktop/Development/playground/toggl2 folder. Either provide one or disable Service Worker in your angular.json configuration file.
Edit 3 & 'Solution' 09.05.2018
This issues is supposed to get fixed if this Pull Request from 1st May 2018 is accepted.
Meanwhile, you can auto-unregister the serviceworker by removing the ngsw.json from the dist/ folder and NOT ngsw-config.json as described in the fail safe section. See reply I got here.
Furthermore it could also be a chrome bug
In our case the problem was resolved after upgrading to angular 6.0.0. If it's possible for your project, you should give that a try.
I looked at the ngsw-worker.js and it changed quite a bit in 6.0.0 compared to (in our case) 5.2.0.
We can work around this error by downgrading service.worker 5.2.10 to 5.2.0 "@angular/service-worker": "5.2.0",
Update
After a second deploy we ran into the same error. Now we have unregistered all service workers in chrome (chrome://serviceworker-internals/) and now it seems to work with version 5.2.10 also. Don't know where the problem lies.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With