Schematics error: Cannot read property 'length' of undefined
See original GitHub issueBug Report
Current behavior
If you generate a module with nest g mo core/module
in order to have a module called DatabaseModule into your CoreModule then throws an error like:
TypeError: Cannot read property 'length' of undefined
at MetadataManager.insertSymbolToMetadata (G:\mis-cursos\quiz-api\node_modules\@nestjs\schematics\dist\utils\metadata.manager.js:104:33)
at MetadataManager.insert (G:\mis-cursos\quiz-api\node_modules\@nestjs\schematics\dist\utils\metadata.manager.js:41:25)
at ModuleMetadataDeclarator.declare (G:\mis-cursos\quiz-api\node_modules\@nestjs\schematics\dist\utils\module-metadata.declarator.js:7:34)
at ModuleDeclarator.declare (G:\mis-cursos\quiz-api\node_modules\@nestjs\schematics\dist\utils\module.declarator.js:14:33)
at G:\mis-cursos\quiz-api\node_modules\@nestjs\schematics\dist\lib\module\module.factory.js:53:51
at MergeMapSubscriber.project (G:\mis-cursos\quiz-api\node_modules\@nestjs\schematics\node_modules\@angular-devkit\schematics\src\rules\call.js:74:24)
at MergeMapSubscriber._tryNext (G:\mis-cursos\quiz-api\node_modules\@nestjs\schematics\node_modules\rxjs\internal\operators\mergeMap.js:69:27)
at MergeMapSubscriber._next (G:\mis-cursos\quiz-api\node_modules\@nestjs\schematics\node_modules\rxjs\internal\operators\mergeMap.js:59:18)
at MergeMapSubscriber.Subscriber.next (G:\mis-cursos\quiz-api\node_modules\@nestjs\schematics\node_modules\rxjs\internal\Subscriber.js:66:18)
at MergeMapSubscriber.notifyNext (G:\mis-cursos\quiz-api\node_modules\@nestjs\schematics\node_modules\rxjs\internal\operators\mergeMap.js:92:26)
Failed to execute command: "G:\mis-cursos\quiz-api\node_modules\@nestjs\cli\node_modules\.bin\schematics" @nestjs/schematics:module --name=core/database --no-dry-run --collection="@nestjs/schematics" --language="ts" --sourceRoot="src" --spec
Possible Solution
The work around is creating it manually.
Environment
Nest version: X.Y.Z
```bash
➜ quiz-api git:(master) nest info
_ _ _ ___ _____ _____ _ _____
| \ | | | | |_ |/ ___|/ __ \| | |_ _|
| \| | ___ ___ | |_ | |\ `--. | / \/| | | |
| . ` | / _ \/ __|| __| | | `--. \| | | | | |
| |\ || __/\__ \| |_ /\__/ //\__/ /| \__/\| |_____| |_
\_| \_/ \___||___/ \__|\____/ \____/ \____/\_____/\___/
[System Information]
OS Version : Windows 10
NodeJS Version : v12.16.2
YARN Version : 1.22.4
[Nest CLI]
Nest CLI Version : 7.1.5
[Nest Platform Information]
platform-express version : 7.0.9
mongoose version : 6.4.0
common version : 7.0.9
config version : 0.4.0
core version : 7.0.9
```
Others:
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (1 by maintainers)
Top Results From Across the Web
ERROR in Cannot read property 'length' of undefined ERROR ...
... I am getting exception ERROR in Cannot read property 'length' of undefined ERROR in multi ./node_modules/bootstrap/scss/bootstrap.scss .
Read more >Cannot Read Property Length of Undefined in JavaScript
The JavaScript TypeError: Cannot read property 'length' of undefined occurs when the length property is read on an undefined variable.
Read more >ERROR in Cannot read property 'length&
I got an error. ERROR in Cannot read property 'length' of undefined. The problem resolved when I deleted the following line from the...
Read more >Cannot read property 'length' of undefined -v - Ionic Forum
[ERROR] An error occurred while running subprocess Cordova. cordova.cmd build android --device exited with exit code 1. Re-running this command ...
Read more >The "Cannot read property 'length' of undefined" error occurs if ...
This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Another case: Your ‘app.module.ts’ (or ‘libName.module.ts’) edited.
update with:
‘imports: …’ must end with: ‘]’
This issue happened on upgrade, then after deleting node_modules directory it has dissapeared. Just noticed of that. Clossing the issue.