angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

Can't generate library

Open mackelito opened this issue 8 years ago • 15 comments

Bug Report or Feature Request (mark with an x)

- [ x ] bug report -> please search issues before submitting

Command (mark with an x)

- [ x ] generate

Versions

npm: 6.2.0 Angular CLI: 6.1.3 Node: 10.8.0 OS: darwin x64 Angular: 6.1.2 ... 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.5 @angular-devkit/build-angular 0.6.5 @angular-devkit/build-optimizer 0.6.5 @angular-devkit/core 0.7.3 @angular-devkit/schematics 0.7.3 @angular/cdk 6.4.3 @angular/cli 6.1.3 @angular/flex-layout 6.0.0-beta.17 @angular/material 6.4.3 @angular/pwa 0.6.8 @ngtools/webpack 6.0.5 @schematics/angular 0.6.8 @schematics/update 0.7.3 rxjs 6.2.2 typescript 2.9.2 webpack 4.8.3

Repro steps

ng g library core --prefix=fc

The log given by the failure

Cannot read property 'entries' of undefined

Desired functionality

Would like go get my library :D

Mention any other details that might be useful

I have tested on a fresh project and that works.. My guess is that there is something wonky with the angular.json. We have been using the CLI for some time and belive that the upgrades along the way might have something to do with the issue.

Note: ng g c test works just fine

angular.json file:

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
    "version": 1,
      "newProjectRoot": "projects",
        "projects": {
    "market": {
      "root": "",
        "sourceRoot": "src",
          "projectType": "application",
            "schematics": {
        "@schematics/angular:component": {
          "changeDetection": "OnPush",
            "prefix": "fcd",
              "styleext": "scss"
        },
        "@schematics/angular:directive": {
          "prefix": "fcd"
        }
      },
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
            "options": {
            "outputPath": "dist",
              "index": "src/index.html",
                "main": "src/main.ts",
                  "tsConfig": "src/tsconfig.app.json",
                    "polyfills": "src/polyfills.ts",
                      "assets": [
                        "src/assets",
                        "src/favicon.ico",
                        "src/favicon-16x16.png",
                        "src/favicon-32x32.png",
                        "src/manifest.json"
                      ],
                        "styles": [
                          "src/styles.scss"
                        ],
                          "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,
                          "aot": true,
                            "extractLicenses": true,
                              "vendorChunk": false,
                                "buildOptimizer": true,
                                  "serviceWorker": true
            },
            "staging": {
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.staging.ts"
                }
              ],
                "optimization": true,
                  "outputHashing": "all",
                    "sourceMap": true,
                      "extractCss": true,
                        "namedChunks": false,
                          "aot": true,
                            "extractLicenses": true,
                              "vendorChunk": false,
                                "buildOptimizer": true,
                                  "serviceWorker": true
            }
          }
        },
        "serve": {
          "builder": "@angular-devkit/build-angular:dev-server",
            "options": {
            "browserTarget": "market:build",
              "host": "0.0.0.0"
          },
          "configurations": {
            "production": {
              "browserTarget": "market:build:production"
            },
            "staging": {
              "browserTarget": "market:build:staging"
            }
          }
        },
        "extract-i18n": {
          "builder": "@angular-devkit/build-angular:extract-i18n",
            "options": {
            "browserTarget": "market:build"
          }
        },
        "test": {
          "builder": "@angular-devkit/build-angular:karma",
            "options": {
            "main": "src/test.ts",
              "karmaConfig": "./karma.conf.js",
                "polyfills": "src/polyfills.ts",
                  "tsConfig": "src/tsconfig.spec.json",
                    "scripts": [],
                      "styles": [
                        "src/styles.scss"
                      ],
                        "assets": [
                          "src/assets",
                          "src/favicon.ico",
                          "src/manifest.json"
                        ]
          }
        },
        "lint": {
          "builder": "@angular-devkit/build-angular:tslint",
            "options": {
            "tsConfig": [
              "src/tsconfig.app.json",
              "src/tsconfig.spec.json"
            ],
              "exclude": [
                "**/node_modules/**"
              ]
          }
        }
      }
    },
    "market-e2e": {
      "root": "e2e/",
        "sourceRoot": "",
          "projectType": "application",
            "architect": {
        "e2e": {
          "builder": "@angular-devkit/build-angular:protractor",
            "options": {
            "protractorConfig": "./protractor.conf.js",
              "devServerTarget": "market:serve"
          }
        },
        "lint": {
          "builder": "@angular-devkit/build-angular:tslint",
            "options": {
            "tsConfig": [
              "e2e/tsconfig.e2e.json"
            ],
              "exclude": []
          }
        }
      }
    }
  },
  "defaultProject": "market",
    "cli": {
    "packageManager": "yarn"
  }
}

mackelito avatar Aug 14 '18 08:08 mackelito

I have tried this with the latest beta using your angular.json and I cannot reproduce the issue.

alan-agius4 avatar Aug 14 '18 09:08 alan-agius4

@alan-agius4 any ideas on where I can keep digging?

mackelito avatar Aug 14 '18 09:08 mackelito

Can you try to update all devkit packages to the same latest version 0.7.3?

alan-agius4 avatar Aug 14 '18 10:08 alan-agius4

updated to "@angular-devkit/build-angular": "0.7.3".. reinstalled.. no cigarr :(

mackelito avatar Aug 14 '18 11:08 mackelito

running

rm -rf node_modules/

and then

ng g library core --prefix=fc

worked... But only if I did NOT install before.. (using yarn or npm)

mackelito avatar Aug 14 '18 11:08 mackelito

Can you share you package.json?

alan-agius4 avatar Aug 14 '18 11:08 alan-agius4

{
  "name": "market",
  "version": "0.0.1",
  "license": "MIT",
  "scripts": {
    "ng": "ng",
    "start": "ng serve --proxy-config proxy.conf.json --aot",
    "ssl": "ng serve --configuration=production --proxy-config proxy.conf.json --aot --prod --ssl true --ssl-key /ssl/server.key --ssl-cert /ssl/server.crt",
    "analyze": "ng build --prod --stats-json && webpack-bundle-analyzer dist/stats.json",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e",
    "staging": "ng build --prod --configuration=staging",
    "prod": "ng build --prod --configuration=production",
    "reload-nginx": "sh ./scripts/reload-nginx"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "6.1.2",
    "@angular/cdk": "^6.4.3",
    "@angular/common": "6.1.2",
    "@angular/compiler": "6.1.2",
    "@angular/core": "6.1.2",
    "@angular/flex-layout": "6.0.0-beta.17",
    "@angular/forms": "6.1.2",
    "@angular/http": "6.1.2",
    "@angular/material": "^6.4.3",
    "@angular/platform-browser": "6.1.2",
    "@angular/platform-browser-dynamic": "6.1.2",
    "@angular/pwa": "^0.6.8",
    "@angular/router": "6.1.2",
    "@angular/service-worker": "6.1.2",
    "@types/file-saver": "^1.3.0",
    "@types/lodash-es": "^4.17.0",
    "@types/moment-timezone": "^0.5.4",
    "autotrack": "^2.4.1",
    "classlist.js": "^1.1.20150312",
    "core-js": "^2.5.3",
    "file-saver": "^1.3.3",
    "hammerjs": "^2.0.8",
    "in-view": "^0.6.1",
    "intersection-observer": "^0.4.2",
    "localforage": "^1.7.1",
    "lodash-es": "^4.17.10",
    "moment": "^2.20.1",
    "moment-timezone": "^0.5.17",
    "rxjs": "6.2.2",
    "stacktrace-js": "^2.0.0",
    "web-animations-js": "^2.3.1",
    "zone.js": "^0.8.26"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "0.7.3",
    "@angular-devkit/build-ng-packagr": "~0.7.0",
    "@angular/cli": "6.1.3",
    "@angular/compiler-cli": "6.1.2",
    "@angular/language-service": "6.1.2",
    "@types/google.analytics": "^0.0.36",
    "@types/hammerjs": "^2.0.35",
    "@types/jasmine": "~2.5.53",
    "@types/jasminewd2": "~2.0.2",
    "@types/node": "~6.0.60",
    "codelyzer": "~4.2.1",
    "jasmine-core": "~2.6.2",
    "jasmine-spec-reporter": "~4.1.0",
    "karma": "~1.7.0",
    "karma-chrome-launcher": "~2.1.1",
    "karma-cli": "~1.0.1",
    "karma-coverage-istanbul-reporter": "^1.2.1",
    "karma-jasmine": "~1.1.0",
    "karma-jasmine-html-reporter": "^0.2.2",
    "ng-packagr": "^3.0.0",
    "protractor": "~5.1.2",
    "stylelint": "^9.2.1",
    "stylelint-config-standard": "^18.2.0",
    "stylelint-scss": "^3.1.0",
    "ts-node": "~3.2.0",
    "tsickle": ">=0.29.0",
    "tslib": "^1.9.0",
    "tslint": "~5.3.2",
    "typescript": "2.9.2",
    "webpack-bundle-analyzer": "^2.13.1"
  },
  "browserslist": [
    "last 2 versions",
    "not ie <= 10",
    "not ie_mob <= 10"
  ]
}

mackelito avatar Aug 14 '18 11:08 mackelito

Does this work by any chance npm run ng g library core --prefix=fc?

Maybe you can provide a small reproduction so that we can trace what's the root cause?

alan-agius4 avatar Aug 14 '18 12:08 alan-agius4

is there anything more provided in the error message?

alexeagle avatar Aug 14 '18 13:08 alexeagle

I am getting the same error message. Running yarn ng g lib mylib --debug I get the following output:

$ ng g lib mylib --debug
An error occured:
Cannot read property 'entries' of undefined
TypeError: Cannot read property 'entries' of undefined
    at new FilteredTree (/abc/node_modules/@schematics/angular/node_modules/@angular-devkit/schematics/src/tree/filtered.js:13:18)
    at /abc/node_modules/@schematics/angular/node_modules/@angular-devkit/schematics/src/rules/base.js:82:22
    at MergeMapSubscriber.input.pipe.operators_1.mergeMap.inputTree [as project] (/abc/node_modules/@schematics/angular/node_modules/@angular-devkit/schematics/src/rules/call.js:77:24)
    at MergeMapSubscriber._tryNext (/abc/node_modules/rxjs/internal/operators/mergeMap.js:65:27)
    at MergeMapSubscriber._next (/abc/node_modules/rxjs/internal/operators/mergeMap.js:55:18)
    at MergeMapSubscriber.Subscriber.next (/abc/node_modules/rxjs/internal/Subscriber.js:64:18)
    at Observable._subscribe (/abc/node_modules/rxjs/internal/observable/scalar.js:6:20)
    at Observable._trySubscribe (/abc/node_modules/rxjs/internal/Observable.js:43:25)
    at Observable.subscribe (/abc/node_modules/rxjs/internal/Observable.js:29:22)
    at MergeMapOperator.call (/abc/node_modules/rxjs/internal/operators/mergeMap.js:35:23)
error Command failed with exit code 1.

Even after creating a fresh workspace (with nrwl nx) there are some issues with the creation of apps / libraries. Running yarn ng g app myapp --debug results in the following output:

$ ng g app myapp --debug
An error occured:
Cannot read property 'kind' of undefined
TypeError: Cannot read property 'kind' of undefined
    at _angularImportsFromNode (/abc/node_modules/@schematics/angular/utility/ast-utils.js:187:16)
    at findNodes.map (/abc/node_modules/@schematics/angular/utility/ast-utils.js:230:24)
    at Array.map (<anonymous>)
    at Object.getDecoratorMetadata (/abc/node_modules/@schematics/angular/utility/ast-utils.js:230:10)
    at _addSymbolToNgModuleMetadata (/abc/node_modules/@nrwl/schematics/src/utils/ast-utils.js:28:29)
    at Object.addImportToModule (/abc/node_modules/@nrwl/schematics/src/utils/ast-utils.js:213:12)
    at /abc/node_modules/@nrwl/schematics/src/collection/application/index.js:27:30
    at MergeMapSubscriber.input.pipe.operators_1.mergeMap.inputTree [as project] (/abc/node_modules/@angular-devkit/schematics/src/rules/call.js:74:24)
    at MergeMapSubscriber._tryNext (/abc/node_modules/rxjs/internal/operators/mergeMap.js:65:27)
    at MergeMapSubscriber._next (/abc/node_modules/rxjs/internal/operators/mergeMap.js:55:18)
error Command failed with exit code 1.

The second error can be solved by upgrading to Typescript 2.9.2 but unfortunately this does not work for the first one.

martinbdz avatar Aug 14 '18 16:08 martinbdz

Same issue with ng g m <module name>.

Cannot read property 'entries' of undefined

npx ng -v

Angular CLI: 6.1.3 Node: 10.8.0 OS: win32 x64 Angular: 6.1.2 ... animations, common, compiler, compiler-cli, core, forms ... http, language-service, platform-browser ... platform-browser-dynamic, router, service-worker

Package Version

@angular-devkit/architect 0.7.3 @angular-devkit/build-angular 0.7.3 @angular-devkit/build-optimizer 0.7.3 @angular-devkit/build-webpack 0.7.3 @angular-devkit/core 0.7.3 @angular-devkit/schematics 0.7.3 @angular/cdk 6.4.5 @angular/cli 6.1.3 @angular/material 6.4.5 @angular/pwa 0.6.8 @ngtools/webpack 6.1.3 @schematics/angular 0.6.8 @schematics/update 0.7.3 rxjs 6.2.2 typescript 2.9.2 webpack 4.9.2

UPD1: ng g m <module name> --routing still work, but as soon as i remove --routing flag it throws me "Cannot read property 'entries' of undefined"

vildhjarta8 avatar Aug 15 '18 08:08 vildhjarta8

I have the same error message (Cannot read property 'entries' of undefined) when I run my custom schematics on Angular 7. The same schematics on Angular 6 works as intended. After commenting line with filtering - it's working with no errors:

schematics_1.mergeWith(schematics_1.apply(schematics_1.url('./files'), [
    // schematics_1.filter(path => path.endsWith('app.config')),
   schematics_1.template(Object.assign({}, core_1.strings, options, preparedValues))
])),

Update: It also works after deleting local node_modules of my schematics, so schematics will use node_modules installed in workspace folder. These (dev)dependencies are part of package.json file:

"dependencies": {
    "@angular-devkit/core": "^0.6.5",
    "@angular-devkit/schematics": "^0.6.5",
    "@schematics/angular": "^0.6.5",
    "semver": "^5.5.0",
    "typescript": ">=2.6.2 <2.8"
},
"devDependencies": {
    "@types/jasmine": "^2.6.0",
    "@types/node": "^8.0.31",
    "jasmine": "^2.8.0",
    "json-schema-to-typescript": "^5.3.3"
}

What happens? Is it some braking change between 6.x and 7.x or I have to reduce schematics (dev)dependencies list in order to utilize project's dependencies?

mnicic avatar Oct 04 '18 12:10 mnicic

Hi, can you try to update the@angular-devkit/<packages> to the latest versions and see if you are able to reproduce the issue?

My thoughts are, that those versions (which are pretty old) are not compatible with the latest versions.

alan-agius4 avatar Jan 15 '19 17:01 alan-agius4

Closing as no further information provided by the original reporter.

Kindly try to update to the latest packages and if the problem persist kindly open a new issue with a minimal reproduction of the error.

Thanks.

alan-agius4 avatar Feb 12 '19 13:02 alan-agius4

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.