Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
1 of 15 tasks
mjamin opened this issue Jul 22, 2021 · 9 comments · Fixed by #22934
Closed
1 of 15 tasks
Assignees
Labels
area: @schematics/angular freq1: low Only reported by a handful of users who observe it rarely severity3: broken type: bug/fix
Milestone

Comments

@mjamin
Copy link

mjamin commented Jul 22, 2021

🐞 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

@ngbot ngbot bot added this to the Backlog milestone Jul 22, 2021
@iftee-hussain
Copy link
Contributor

If the issue is not taken, I would like to give it a try.

@tejas10191
Copy link

tejas10191 commented Jul 31, 2021

I'm gonna give it a try too.

@tejas10191
Copy link

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

@iftee-hussain
Copy link
Contributor

iftee-hussain commented Jul 31, 2021

IMO it should skip the candidate file path without having moduleExt

@kuldeepvishwakarma05
Copy link

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

@aakash1003
Copy link

if this is not resolved yet, then I would like to give it a try

@Allencs16
Copy link

I would like to try too if is not fixed

@msarfrazanwar
Copy link

What is the expected fix for this Issue ? Append ".module.ts" after name pass in cli ?

@alan-agius4 alan-agius4 self-assigned this Apr 1, 2022
clydin pushed a commit that referenced this issue Apr 4, 2022
…ng declaration cannot be found

Due to incorrect castings previously the code would crash when the module doesn't contain an routing module with the following error:

```
Cannot read property 'properties' of undefined
```

Closes #21397

(cherry picked from commit 7db433b)
clydin pushed a commit that referenced this issue Apr 4, 2022
…ng declaration cannot be found

Due to incorrect castings previously the code would crash when the module doesn't contain an routing module with the following error:

```
Cannot read property 'properties' of undefined
```

Closes #21397
@angular-automatic-lock-bot
Copy link

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.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators May 5, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: @schematics/angular freq1: low Only reported by a handful of users who observe it rarely severity3: broken type: bug/fix
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants