🐞 Bug report
Command (mark with an x)
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
🐞 Bug report
Command (mark with an
x)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,findModuleFromOptionstries file candidates from least to most specific: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 undefinederror down the line (node is undefined ingetMetadataFieldin ast-utils).🔬 Minimal Reproduction
ng new.src/app/app.tsng g m foo --routing --route=foo --module=app🔥 Exception or Error
Cannot read property 'properties' of undefined🌍 Your Environment
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