error when invoking 'generate module' and there's no nestjs module to update
micalevisk opened this issue · comments
Is there an existing issue for this?
- I have searched the existing issues
Current behavior
when using nest generate module
and there's no occurrence of @Module()
of some .module.ts
file at the entry dir, the CLI breaks with the following error:
Error: Cannot read properties of undefined (reading 'properties')
Failed to execute command: node @nestjs/schematics:module --name=foo --no-dry-run --no-skip-import --language="ts" --source-root="src" --no-spec --no-flat --spec-file-suffix="spec"
Minimum reproduction code
https://gitlab.com/micalevisk/nestjs-schematics-issue-1444
Steps to reproduce
git clone https://gitlab.com/micalevisk/nestjs-schematics-issue-1444.git
cd nestjs-schematics-issue-1444
npm ci
npx nest g module foo
- see the error
the reason is pretty clear here:
schematics/src/utils/metadata.manager.ts
Lines 33 to 37 in e4d2c54
those lines didn't cover the scenario of decoratorNodes.length === 0
Expected behavior
The CLI should create the module without updating any other existing module, just like when there's no .module.ts
file
Package version
9.2.0
NestJS version
No response
Node.js version
18
In which operating systems have you tested?
- macOS
- Windows
- Linux
Other
I tried to fix that already but didn't succeeded. I need more time to understand that metadata.manager.ts
Good catch! If you want to create a PR for this issue, that would be great! I believe adding a simple if
condition should be enough(?)