Uncaught TypeError: Cannot read property 'id' of undefined at registerNgModuleType - angular PWA

Arter picture Arter · Nov 20, 2019 · Viewed 14.6k times · Source

after adding @angular/pwa to my app

ng add @angular/pwa --project appName

I get error

core.js:34469 Uncaught TypeError: Cannot read property 'id' of undefined at registerNgModuleType

If I in my appName.module.ts remove from imports

ServiceWorkerModule.register("ngsw-worker.js", {
  enabled: environment.production
})

app working again.

Angular.json is added

"serviceWorker": true,
"ngswConfigPath": "projects/tol5-admin-app/ngsw-config.json"

Here is my package.json

 "private": true,
  "dependencies": {
    "@angular/animations": "~8.2.5",
    "@angular/cdk": "~8.2.2",
    "@angular/common": "~8.2.5",
    "@angular/compiler": "~8.2.5",
    "@angular/core": "~8.2.5",
    "@angular/flex-layout": "^8.0.0-beta.27",
    "@angular/forms": "~8.2.5",
    "@angular/material": "^8.2.2",
    "@angular/platform-browser": "~8.2.5",
    "@angular/platform-browser-dynamic": "~8.2.5",
    "@angular/router": "~8.2.5",
    "@angular/service-worker": "~8.2.5",
    "@ngrx/effects": "^8.3.0",
    "@ngrx/schematics": "^8.4.0",
    "@ngrx/store": "^8.3.0",
    "@ngrx/store-devtools": "^8.3.0",
    "font-awesome": "^4.7.0",
    "hammerjs": "^2.0.8",
    "jquery": "^3.4.1",
    "rxjs": "~6.4.0",
    "tslib": "^1.10.0",
    "zone.js": "~0.9.1"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.803.4",
    "@angular/cli": "~8.3.4",
    "@angular/compiler-cli": "~8.2.5",
    "@angular/language-service": "~8.2.5",
    "@compodoc/compodoc": "^1.1.11",
    "@types/node": "~8.9.4",
    "codelyzer": "^5.0.0",
    "protractor": "~5.4.0",
    "rxjs-tslint-rules": "^4.26.1",
    "ts-node": "~7.0.0",
    "tslint": "~5.15.0",
    "tslint-angular": "^3.0.2",
    "typescript": "~3.5.3",
    "webpack-bundle-analyzer": "^3.6.0"
  }
}

Answer

Jai picture Jai · Mar 25, 2020

This often happens when you've mixed up imports and declarations in the pertinent module (or some other such mix-up). You might for example have put a component in the imports array, where only modules should be 'declared'. The component should be in the declarations array.