question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Schematics error: Cannot read property 'length' of undefined

See original GitHub issue

Bug 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:closed
  • Created 3 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
tritoanstcommented, Jul 8, 2020

Another case: Your ‘app.module.ts’ (or ‘libName.module.ts’) edited.

@Module({
  imports: allModules,
  providers: [AppService],
})
export class AppModule {}

update with:

@Module({
  imports: [
    ...allModules,
  ],
  providers: [AppService],
})
export class AppModule {}

‘imports: …’ must end with: ‘]’

1reaction
ruslangunscommented, May 6, 2020

This issue happened on upgrade, then after deleting node_modules directory it has dissapeared. Just noticed of that. Clossing the issue.

Read more comments on GitHub >

github_iconTop 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&#38
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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found