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:
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
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: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 ingetMetadataField
in ast-utils).ng new
.src/app/app.ts
ng g m foo --routing --route=foo --module=app
Cannot read property 'properties' of undefined
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
The text was updated successfully, but these errors were encountered: