question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot read property 'properties' of undefined when adding a lazy loaded module with ng generate

See original GitHub issue

🐞 Bug report

Command (mark with an x)

  • new
  • build
  • serve
  • test
  • e2e
  • generate
  • add
  • update
  • lint
  • extract-i18n
  • run
  • config
  • help
  • version
  • doc

Description

While attempting to find the module to add a lazy loaded route declaration to while generating a new lazy loaded module with option --module=app, findModuleFromOptions tries file candidates from least to most specific:


[
  '/src/app/areas',
  '/src/app/areas/app.ts',
  '/src/app/areas/app.module.ts'
]

If both app.module.ts and app.ts exist, app.ts is returned. If that file does not include an @angular/core import, this leads to an Cannot read property 'properties' of undefined error down the line (node is undefined in getMetadataField in ast-utils).

🔬 Minimal Reproduction

  • Create a new angular project using ng new.
  • Create an empty file src/app/app.ts
  • Call ng g m foo --routing --route=foo --module=app

🔥 Exception or Error

Cannot read property 'properties' of undefined

🌍 Your Environment


Angular CLI: 12.1.3
Node: 12.18.3
Package Manager: npm 6.14.6
OS: win32 x64

Angular: 12.1.3
... animations, cli, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1201.3
@angular-devkit/build-angular   12.1.3
@angular-devkit/core            12.1.3
@angular-devkit/schematics      12.1.3
@schematics/angular             12.1.3
rxjs                            6.6.7
typescript                      4.3.5

Workaround

To work around this issue, we can specify the module by file name, not module name:

ng g m foo --routing --route=foo --module=app.module.ts

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
kuldeepvishwakarma05commented, Sep 15, 2021

Angular CLI: 12.1.3 Node: 12.18.3 Package Manager: npm 6.14.6 OS: win32 x64

Angular: 12.1.3 … animations, cli, common, compiler, compiler-cli, core, forms … platform-browser, platform-browser-dynamic, router

Package Version

@angular-devkit/architect 0.1201.3 @angular-devkit/build-angular 12.1.3 @angular-devkit/core 12.1.3 @angular-devkit/schematics 12.1.3 @schematics/angular 12.1.3 rxjs 6.6.7 typescript 4.3.5

1reaction
tejas10191commented, Jul 31, 2021

@alan-agius4 Ideally, it should skip the file-path without module.ts extension ?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot read properties of undefined (reading 'loadChildren')
I'm moving an existing Angular 10 project into a new multi-project workspace without changing the source. After creating the workspace and ...
Read more >
cannot read property of undefined angular testing - You.com
Run default angular (karma) test on any component, make sure to import CoreTestingModule, IdentityConfigModule and TenantManagementConfigModule. Also add ...
Read more >
Singleton services - Angular
Only the root AppModule should import the GreetingModule . If a lazy-loaded module imports it too, the application can generate multiple instances of...
Read more >
How to Lazy Load a Component in Angular - Telerik
Create the Lazy-Loaded Component ... In the application, add a new component using the Angular CLI command, as shown below. ... Here --skip-import ......
Read more >
Cannot read properties of undefined (reading 'routes') - Reddit
If i remove the forChild code, and just leave the component. The error goes away. The authModule has no routes so I have...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found