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

@angular/pwa cannot refresh pwa after rebuild - Driver.<anonymous> (ngsw-worker.js:1988) property 'id' of undefined #23742

Closed
andrew19881123 opened this issue May 7, 2018 · 12 comments
Labels
area: service-worker Issues related to the @angular/service-worker package
Milestone

Comments

@andrew19881123
Copy link

andrew19881123 commented May 7, 2018

I'm submitting a...

[x] Bug report

Current behavior

  1. I create a new angular 6 project with the cli and adding the pwa with ng add @angular/pwa
  2. I run ng build --prod
  3. I run http-server -p 8080 dist/angular6/

current behavior: the app starts at http://localhost:8080/ and i can see the browser downloading all the files including the service workers, if i put the browser offline i can still see the app and the resources fetched by the sw.

  1. I change the html of the app.component.html
  2. I run ng build --prod
  3. I run http-server -p 8080 dist/angular6/
  4. Refresh the browser in http://localhost:8080/

I get this error:

ngsw-worker.js:1988 Uncaught (in promise) TypeError: Cannot read property 'id' of undefined
    at Driver.<anonymous> (ngsw-worker.js:1988)
    at Generator.next (<anonymous>)
    at __awaiter (ngsw-worker.js:1755)
    at new Promise (<anonymous>)
    at __awaiter (ngsw-worker.js:1751)
    at Driver.updateClient (ngsw-worker.js:1985)
    at Driver.<anonymous> (ngsw-worker.js:2224)
    at Generator.next (<anonymous>)
    at fulfilled (ngsw-worker.js:1752)

Environment


{
  "name": "angular6",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build --prod",
    "sw":"http-server -p 8080 dist/angular6/",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^6.0.0",
    "@angular/common": "^6.0.0",
    "@angular/compiler": "^6.0.0",
    "@angular/core": "^6.0.0",
    "@angular/forms": "^6.0.0",
    "@angular/http": "^6.0.0",
    "@angular/platform-browser": "^6.0.0",
    "@angular/platform-browser-dynamic": "^6.0.0",
    "@angular/pwa": "^0.6.0",
    "@angular/router": "^6.0.0",
    "core-js": "^2.5.4",
    "rxjs": "^6.0.0",
    "zone.js": "^0.8.26",
    "@angular/service-worker": "^6.0.0"
  },
  "devDependencies": {
    "@angular/compiler-cli": "^6.0.0",
    "@angular-devkit/build-angular": "~0.6.0",
    "typescript": "~2.7.2",
    "@angular/cli": "~6.0.0",
    "@angular/language-service": "^6.0.0",
    "@types/jasmine": "~2.8.6",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "~8.9.4",
    "codelyzer": "~4.2.1",
    "jasmine-core": "~2.99.1",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~1.7.1",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~1.4.2",
    "karma-jasmine": "~1.1.1",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.3.0",
    "ts-node": "~5.0.1",
    "tslint": "~5.9.1"
  }
}


Browser:
- [x] Chrome (desktop) version 66.0.3359.139
 
For Tooling issues:
- Node version: 10.0.0
- NPM version: 6.0.0
- Platform:  OSX
@niikoo
Copy link

niikoo commented May 8, 2018

I've used this fix for that issue:

ngsw-worker.js:2208

Replace:
if (clientId !== null) {
With:
if (clientId !== null && clientId !== '') {

Why?
Because I've seen clientId's that are empty strings instead of null.

@aavelyn
Copy link

aavelyn commented May 8, 2018

I got the exact same error
(https://stackoverflow.com/questions/50161482/angular-cli-update-service-worker-id-of-undefined-error)
But already on angular-cli v1.7.4 and Angular v.5.2.10

Edit

@niikoo your solution has the side effect, that the browser will treat the new ngsw-worker.js as a new SW to replace the old one. I'm not sure how the versioning or updating is being done but essentially ng build prod does generate the exact same SW each time, which then loads a different ngsw.json.

@mhevery mhevery added the area: service-worker Issues related to the @angular/service-worker package label May 8, 2018
@ngbot ngbot bot added this to the needsTriage milestone May 8, 2018
@ratfury
Copy link

ratfury commented May 9, 2018

We have the same error but only in Chrome (Version 66.0.3359.139) the webapp won't load.
With "@angular/service-worker": "5.2.0", everything seems to work fine.

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.

@Kristian1138
Copy link

Kristian1138 commented May 9, 2018

For me, the workaround to get NG6 PWA to be able to refresh was posted by Dirand and Argentan angular-cli/issues/8779.

Dirand suggested to check if application is stable:
import { ApplicationRef } from '@angular/core';
...
constructor( private _application: ApplicationRef ) {}
...

 ngOnInit() {
    this._application.isStable.subscribe((s) => {
      if (s) {
        setInterval(t => { console.log('Ping')}, 500);
      }
    });

    this._application.isStable.subscribe(t => {
      console.log('App stable: ' + t);
    });
}

Argentan suggested to register the service worker in main.ts:

platformBrowserDynamic().bootstrapModule(AppModule).then(() => {
  if ('serviceWorker' in navigator && environment.production) {
    navigator.serviceWorker.register('/ngsw-worker.js');
  }
}).catch(err => console.log(err));

@gkalpak
Copy link
Member

gkalpak commented May 9, 2018

Duplicate of #23526. (Fix is on its way: #23625)

@gkalpak gkalpak closed this as completed May 9, 2018
@walle233
Copy link

same error,who can help me.

@gkalpak
Copy link
Member

gkalpak commented May 16, 2018

@walle233, the fix has been merged a while ago. It is in the latest 6.x version and will be in the next 5.x release as well. What version are you using?

@walle233
Copy link

walle233 commented Jun 8, 2018

@gkalpak i use 5.x version.thank you for reply to me.

ademidun added a commit to ademidun/atila-angular that referenced this issue Aug 6, 2018
update @angular/service-worker to 5.2.11 see: angular/angular#23742 and angular/angular#23625. Also made manifest.json look nicer
@gaetanmallet
Copy link

I have same error.
"@angular/core": "5.2.0",
"@angular/service-worker": "5.2.0"

@gaetanmallet
Copy link

gaetanmallet commented Sep 28, 2018

@walle233, the fix has been merged a while ago. It is in the latest 6.x version and will be in the next 5.x release as well. What version are you using?

If i check the date of your answer, the fix should be in the 5.2.11, i will try to update all my angular packages to this release and give you a feedback.

@gaetanmallet
Copy link

gaetanmallet commented Sep 28, 2018

@walle233, the fix has been merged a while ago. It is in the latest 6.x version and will be in the next 5.x release as well. What version are you using?

If i check the date of your answer, the fix should be in the 5.2.11, i will try to update all my angular packages to this release and give you a feedback.

It seems to work @gkalpak, i did not see the 5.2.11 before because it is between the 6.x releases.

Good job guys ! Thanks 💪

@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 14, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: service-worker Issues related to the @angular/service-worker package
Projects
None yet
Development

No branches or pull requests

9 participants