Angular-cli: Cannot read property 'entries' of undefined

Created on 20 Aug 2018  路  15Comments  路  Source: angular/angular-cli

[x ] bug report
I am submitting this as a bug because there is no clear and definitive answer on how to troubleshoot this issue. It seems to be effecting developers in different ways and / or for different reasons.

Command

- [ x] generate

Versions

npm --version 5.6.0
macOS --version High Sierra
Angular CLI: 6.1.4
Node: 8.11.4
OS: darwin x64
Angular: 6.1.3
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router, service-worker

Package Version

@angular-devkit/architect 0.6.8
@angular-devkit/build-angular 0.6.8
@angular-devkit/build-optimizer 0.6.8
@angular-devkit/core 0.6.8
@angular-devkit/schematics 0.6.8
@angular/cli 6.1.4
@angular/pwa 0.6.8
@ngtools/webpack 6.0.8
@schematics/angular 0.6.8
@schematics/update 0.7.4
rxjs 6.2.2
typescript 2.9.2
webpack 4.8.3

Repro steps

ng generate command fails for all types component, module, etc, with the following dreaded error:

Cannot read property 'entries' of undefined

with the debug flag, i am seeing this:
at new FilteredTree (/Users/mike/myapp/node_modules/@angular-devkit/schematics/src/tree/filtered.js:13:18)

Maybe it is worth digging into @angular-devkit to figure this out myself. :/

Mention any other details that might be useful

I have already tried removing the node_modules directory and re-installing.

Also tried removing node, npm and angular-cliall together followed by clean installs of each.

In my particular case...

Important to note, that ng serve and ng build are functioning correctly despite the problem with generate.

Also, generating a new project works, as well as using generate within the new project directory OK, so where do i begin to troubleshoot this issue in my existing project?

ANY help greatly appreciated.

schematicangular

Most helpful comment

@gitdisrupt , I had the same issue, I tried to update @angular/pwa package to version ~0.7.5, and this resolved the problem for me.

All 15 comments

I think this might be a duplicate of the issue #11885.

Hi @martinbdz i created this issue because that issue you are referring to is different. This problem seems to be effecting people in different ways. His issue is different from mine.

What id like to see here is a clear set of instructions on how to begin troubleshooting this error.

Creating a new project and slowly migrating all of my app src over seems like a nightmare of a task that in theory should be avoidable.

I am having this issue as well, but only for some of the schematics. For instance creating a module does not work. Some other schematics from ngrx are also not working, but some do. Creating a new project folder and moving the whole app over to it fixed the problem for me for a bit, then it started happening again. I am on a MAC.

I'm having the same issue. But only with ng g module xxx for other generation it's works fine.

I'm on MAC
Angular CLI : 6.1.4

In filtered.js, line 13 where the error was triggered, the following forEach loop exists:

[...root.entries()].forEach(([path, entry]) => {
            if (filter(path, entry)) {
                this._tree.set(path, entry);
            }
});

Can anyone explain what this loops through? What constitutes an 'entry'? Understanding this might help in understanding why the CLI is failing to generate files.

@gitdisrupt , I had the same issue, I tried to update @angular/pwa package to version ~0.7.5, and this resolved the problem for me.

I had the same issue. In my case, it was outdated angular.json. Try to rename "targets" keys in angular.json to "architect".
Before:
``` ....
"schematics": {
},
"targets": {
"build": {
....

After:

```  ....
      "schematics": {
      },
      "architect": {
        "build": {
      ....

Same here ng g c components/test works fine, but ng g c components/test --spec=false don't.
No idea how to solve this, any advices would be appreciated.

Angular-cli: 6.2.2
Node: 8.12.0
npm: 6.4.1
typescript: 2.9.2
OS: Windows 10

getting the below issue when i tried "ng new angular-fundamentals" command

ERROR :: * Cannot read property 'entries' of undefined*

Tried uninstall and installing of node & npm still did not work.

I solved my specific case.

Thanks to @hvedir. His results noted above sent me in the right direction.

The issue was due to an incompatibility in my angular.json file as well.

My project was originally generated using an older version of the Angular CLI. Offhand i could not tell you the exact version number, but i can tell you it was sometime after the release of Angular v4.

The key takeaway being that i had originally generated my project with the --skip-tests flag which set the "schematics" accordingly in the original angular-cli.json file in a format not compatible with Angular v6.

The --skip-tests flag when used along with ng new at that time had set my schematics as follows:

"schematics": {
        "@schematics/angular:component": {
          "styleext": "scss",
          "spec": false
        },
        "@schematics/angular:class": {
          "spec": false
        },
        "@schematics/angular:directive": {
          "spec": false
        },
        "@schematics/angular:guard": {
          "spec": false
        },
        "@schematics/angular:module": {
          "spec": false
        },
        "@schematics/angular:pipe": {
          "spec": false
        },
        "@schematics/angular:service": {
          "spec": false
        }
      }

I had since upgraded my project to Angular 6 manually, using the guide provided, but there was no mention that these settings in particular would need adjustment.

Removing those schematics solved my problem. I just set it to the default:
"schematics": {}

And with that I am now again able to generate all types, service, component, module etc, albeit if i do not want spec files generated moving forward, i need to use the --no-spec flag along with the generate command each time. That is until i can find out how to correctly configure the schematics for Angular v6.

Its possible the correct configuration would need to follow the conventions outlined here, but i have not taken the time to test this just yet:
https://github.com/angular/angular-cli/blob/v6.0.0-rc.8/packages/%40angular/cli/lib/config/schema.json#L71

As mentioned in my comment above, this error seems to fire in varying ways, so i suspect that if anyone else is seeing this error for another reason, digging through your angular.json file is likely a good place to start troubleshooting.

@gitdisrupt , I had the same issue, I tried to update @angular/pwa package to version ~0.7.5, and this resolved the problem for me.

This actually worked for me updated my @angular/pwa to "^0.10.4", hope this will help other people.

I had the same problem and updating @angular/pwa to the latest worked for me

I've tried all fixes outlined above (updated pwa, cli, and devkit) I already had "architect" not "target". We inherited this project and thus the angular.json configuration, so I don't know if they made any weird changes but I looked through the guide on . I'll past the file below, if anyone can take a look and let me know if they see anything out of the ordinary that would be great. I did notice that my defaultCollection under the cli parameter is "@ionic/schematics-angular", but I dug into those and it's just pointing back to the angular schematics for the modules.

{
  "$schema": "./node_modules/@angular-devkit/core/src/workspace/workspace-schema.json",
  "version": 1,
  "defaultProject": "app",
  "projects": {
    "app": {
      "root": "",
      "sourceRoot": "src",
      "projectType": "application",
      "prefix": "app",
      "schematics": {},
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "progress": false,
            "outputPath": "www",
            "index": "src/index.html",
            "main": "src/main.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "src/tsconfig.app.json",
            "assets": [
              {
                "glob": "**/*",
                "input": "src/assets",
                "output": "assets"
              },
              {
                "glob": "**/*.svg",
                "input": "node_modules/@ionic/angular/dist/ionic/svg",
                "output": "./svg"
              },
              {
                "glob": "**/*.json",
                "input": "config",
                "output": "assets"
              },
              {
                "glob": "**/manifest.json",
                "input": "src",
                "output": "."
              },
              {
                "glob": "**/service-worker.js",
                "input": "src",
                "output": "."
              }
            ],
            "styles": [
                "src/global.scss",
                "src/app.scss",
                "node_modules/ngx-toastr/toastr.css"
            ],
            "stylePreprocessorOptions": {
              "includePaths": [
                "src"
              ]
            },
            "scripts": []
          },
          "configurations": {
            "production": {
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.prod.ts"
                }
              ],
              "optimization": true,
              "outputHashing": "all",
              "sourceMap": false,
              "extractCss": true,
              "namedChunks": false,
              "extractLicenses": true,
              "vendorChunk": false
            },
            "dev": {
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.dev.ts"
                }
              ],
              "optimization": false,
              "outputHashing": "none",
              "sourceMap": true,
              "extractCss": true,
              "namedChunks": true,
              "extractLicenses": true,
              "vendorChunk": true
            },
            "test": {
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.test.ts"
                }
              ],
              "optimization": false,
              "outputHashing": "none",
              "sourceMap": true,
              "extractCss": true,
              "namedChunks": true,
              "extractLicenses": true,
              "vendorChunk": false
            }
          }
        },
        "serve": {
          "builder": "@angular-devkit/build-angular:dev-server",
          "options": {
            "browserTarget": "app:build"
          },
          "configurations": {
            "production": {
              "browserTarget": "app:build:production"
            },
            "dev": {
              "browserTarget": "app:build:dev"
            },
            "test": {
              "browserTarget": "app:build:test"
            }
          }
        },
        "extract-i18n": {
          "builder": "@angular-devkit/build-angular:extract-i18n",
          "options": {
            "browserTarget": "app:build"
          }
        },
        "test": {
          "builder": "@angular-devkit/build-angular:karma",
          "options": {
            "environment": "test",
            "fileReplacements": [{
              "replace": "src/environments/environment.ts",
              "with": "src/environments/environment.test.ts"
            }],
            "main": "src/test.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "src/tsconfig.spec.json",
            "karmaConfig": "src/karma.conf.js",
            "styles": [
              "styles.css"
            ],
            "scripts": [],
            "assets": [
              {
                "glob": "favicon.ico",
                "input": "src/",
                "output": "/"
              },
              {
                "glob": "**/*",
                "input": "src/assets",
                "output": "/assets"
              }
            ]
          }
        },
        "lint": {
          "builder": "@angular-devkit/build-angular:tslint",
          "options": {
            "tsConfig": [
              "src/tsconfig.app.json",
              "src/tsconfig.spec.json"
            ],
            "exclude": [
              "**/node_modules/**",
              "**/*.json",
              "**/e2e/**"
            ]
          }
        },
        "ionic-cordova-build": {
          "builder": "@ionic/ng-toolkit:cordova-build",
          "options": {
            "browserTarget": "app:build"
          },
          "configurations": {
            "production": {
              "browserTarget": "app:build:production"
            }
          }
        },
        "ionic-cordova-serve": {
          "builder": "@ionic/ng-toolkit:cordova-serve",
          "options": {
            "cordovaBuildTarget": "app:ionic-cordova-build",
            "devServerTarget": "app:serve"
          },
          "configurations": {
            "production": {
              "cordovaBuildTarget": "app:ionic-cordova-build:production",
              "devServerTarget": "app:serve:production"
            }
          }
        }
      }
    },
    "app-e2e": {
      "root": "e2e/",
      "projectType": "application",
      "architect": {
        "e2e": {
          "builder": "@angular-devkit/build-angular:protractor",
          "options": {
            "protractorConfig": "e2e/protractor.conf.js",
            "devServerTarget": "app:serve"
          }
        },
        "lint": {
          "builder": "@angular-devkit/build-angular:tslint",
          "options": {
            "tsConfig": "e2e/tsconfig.e2e.json",
            "exclude": [
              "**/node_modules/**",
              "**/e2e/**"
            ]
          }
        }
      }
    }
  },
  "cli": {
    "defaultCollection": "@ionic/schematics-angular"
  },
  "schematics": {
    "@ionic/schematics-angular:component": {
      "styleext": "scss"
    },
    "@ionic/schematics-angular:page": {
      "styleext": "scss"
    }
  }
}

Upgraded @schematics/angular to the angular version installed solved to me the problem.

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._

Was this page helpful?
0 / 5 - 0 ratings

Related issues

NCC1701M picture NCC1701M  路  3Comments

JanStureNielsen picture JanStureNielsen  路  3Comments

MateenKadwaikar picture MateenKadwaikar  路  3Comments

sysmat picture sysmat  路  3Comments

donaldallen picture donaldallen  路  3Comments