Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

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

Ask Question

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"
                @JoelJoseph I search and on only one place I use id... and try your solution, but nothing helps. Why this compiled ok and built for production without PWA added in module imports? I think the problem is directly in pwa
– Arter
                Nov 20, 2019 at 12:10

In my case this error occurred seemingly at random. One moment it was working, and the next moment it wasn't. Known working commits were also broken.

I had to delete node_modules and reinstall them which fixed the problem.

A similar thing happened to me as well. I uninstalled an npm module that I no longer needed, but left the import of that module intact in a component. Then ng serve stopped working with the error during app bootstrap. Deleting the node_modules folder and doing a fresh yarn install is what fixed it for me. I think it has something to do with how Angular does module caching in development mode. – praneetloke Sep 17, 2020 at 1:57 It happends if you have update your application name and copy paste in to the another directory, if you missed something in between for your node_modules, you will be getting this error. For fixing this error, you need to removed node_modules directory and run the command npm install – Tejas Savaliya Sep 23, 2020 at 11:05 I assumed this would work after upgrading angular from 8 to 10, but I am still receiving this error, anyone have any advice? – Willie Oct 30, 2020 at 17:08 In my case I executed in yarn script in an npm project. So deleting node_modules and starting afresh solved it. Thanks waylander – Ifelere Bolaji Feb 17, 2021 at 9:39 In my case, I was missing the @ infront of the NgModule decorator. As soon as I corrected it to @NgModule it worked. – Morfinismo Apr 2, 2020 at 19:34 I had the same issue, and realize I have installed the wrong version of Angular Language Service extension. My project had Angular 8 but using the extension of v12, so I downgraded the ALS extension from v12 to v0.8 – samheihey May 20, 2021 at 1:41

In my case, I was running Angular 8 and my project suddenly stoped working (I assumed after a VS code update v 1.56.2)

I resolved this issue by deactivating a VS Code extension called Angular Language Service and deleting the node_modules folder.

Then i run npm install and my project is working since.

My package json dependencies

"dependencies": { "@angular/animations": "8.2.14", "@angular/cdk": "~8.2.3", "@angular/common": "8.2.14", "@angular/compiler": "8.2.14", "@angular/core": "8.2.14", "@angular/forms": "8.2.14", "@angular/http": "7.2.15", "@angular/platform-browser": "8.2.14", "@angular/platform-browser-dynamic": "8.2.14", "@angular/router": "8.2.14", "@microsoft/applicationinsights-web": "~2.5.5", "@ng-bootstrap/ng-bootstrap": "5.0.0", "@ngx-translate/core": "^11.0.1", "@ngx-translate/http-loader": "^4.0.0", "angular-archwizard": "^4.0.0", "animate.css": "^3.7.2", "bootstrap": "4.4.1", "chart.js": "2.8.0", "core-js": "3.5.0", "crypto-js": "^4.0.0", "file-saver": "2.0.2", "flag-icon-css": "^3.4.5", "moment": "2.24.0", "ng2-charts": "2.3.0", "ng2-validation": "^4.2.0", "ngx-mask": "^8.1.6", "ngx-progressbar": "2.1.1", "oidc-client": "1.10.1", "popper": "1.0.1", "rxjs": "6.5.3", "rxjs-compat": "6.5.3", "tslib": "1.10.0", "zone.js": "0.10.2" See my answer below for a fix that allows you to keep the latest angular language service for older versions of angular – Chris Kooken Jan 13, 2022 at 14:20

For me, this issue was related to the VSCode Plugin "Angular Language Service". I upgraded the plugin to the latest, and started getting this error. I am writing a new answer, because I still wanted to use the ALS so here are the steps to resolve it for people who are using ALS (latest) and an older version of angular in my case 8.

Basically what is happening is the new version of ALS uses the IVY engine which creates a bunch of files in node_modules that are not compatible with older versions of angular, so the below steps will fix that.

  • Upgrade to latest ALS (13.1.0)
  • Delete node-modules
  • Edit "Workspace settings" in VSCode and choose "Use legacy view engine language service"
  • Run npm-install
  • Profit.
  • For anyone who deleted node_modules and it worked for a period of time only for the issue to reappear later, give this answer a try. – Joe Newton Jan 24 at 22:21

    in 2021 on 8 angular I faced this issue, just removed node_modules and reinstalled it - issue was solved.

    rm -rf node_modules
    npm install
                    The issue seems to be deeper than that. As this works for a while, the error may appear again. In my case, the issue was resolved after deleting node_modules and running "npm i" again. However the issue repeated itself again. I re-did the same process many times, but the issue keeps coming back after it has worked for a while. Has anyone actually found the reason this may be happening, other than removing the "Angular Language Service" VS Code extention?
    – AlexRebula
                    Aug 22, 2021 at 23:39
                    IMO it depends on the version of the current angular lib in the project and the version of the language service addon. You can try to test this issue from scratch with a clean project, test angular version, next add language service step by step
    – Igor Kurkov
                    Aug 23, 2021 at 12:03
    

    This could happen when you have imported a wrong module inside imports array in module also. One time when working with a reactive forms, I had mistakenly added FormBuilder inside imports rather than ReactiveFormsModule and it gave me the similar error.

    Looks like this error could come from multiple reasons.

  • Disable vs code extension Angular Language Service
  • remove the node modules( rm -rf node_modules)
  • re-install node modules using npm i
  • I noticed that the problem appeared after something was compiling modules in the background – Андрей Керничный Jul 14, 2022 at 11:32

    You should run this command to build your angular app ng build --prod and angular will show you the error detail.

    In my case, I import wrong library from Angular Material.

    ERROR in node_modules/@angular/material/button/button.d.ts:22:22 - error NG6002: Appears in the NgModule.imports of ListeningModule, but could not be resolved to an NgModule class.

    This likely means that the library (@angular/material/button) which declares MatButton has not been processed correctly by ngcc, or is not compatible with Angular Ivy. Check if a newer version of the library is available, and update if so. Also consider checking with the library's authors to see if the library is expected to be compatible with Ivy.

    On Angular 8, I disabled Angular Language Service however, rm-rf node_modules did not work, I just deleted normally on windows. I had to run powershell as administrator then npm install then downgraded Angular Language Service Extention in vs code from 12 to v11.2.13.

    It worked for me.

    As told by jai, I got this issue when I added a component in the imports section. Components should be in the declarations part. moving the SearchFilterComponent to declarations solved this issue.

    import { NgModule } from '@angular/core';
    import { CommonModule } from '@angular/common';
    import { RouterModule } from '@angular/router';
    import { routes } from './admin-settings-menu-routing';
    import { HomeComponent } from './home.component';
    import { SearchFilterComponent } from '../dashboard/common/search-filter/search-filter.component';
    @NgModule({
      declarations: [HomeComponent],
      imports: [
        CommonModule,
        RouterModule.forChild(routes),
       SearchFilterComponent   //Should not be declared here
      providers: []
    export class AdminMenuModule { }

    I have the same problem and I have resolved . I find something in node_modules/angular/* , that means Ivy is work, so I disable it in tsconfig.app.json

    "extends": "../tsconfig.json", "compilerOptions": { "outDir": "../out-tsc/app", "types": ["node"] "exclude": [ "**/*.spec.ts" "angularCompilerOptions": { "enableIvy": false