nestjs / event-emitter

Event Emitter module for Nest framework (node.js) 🦋

Home Page:https://nestjs.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

EventEmitter.emit causes NestJs dependency engine to throw on runtime

donkey-unicornsad opened this issue · comments


[ ] Regression 
[x] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

There's a strange error with NestJs and its event emitter. I have an issue that if I remove an invokation of "emit" method in class A, then class B (which uses it) cannot be resolved Error: Nest can't resolve dependencies of the B (?, C) => A is unknown. When I add this line all works, when I comment it again everything fails.

This is strange, I know. Lack of declaration of method's invokation causes whole class to be undiscoverable by DI. Invokation doesn't take place (since class is not yet instatiated), but it's required for application to start.

When I change the event name it will also throw an error. So I need both invokation AND proper first string. Mystery to me.

I once had it my tests also (i.e. in one spec file). Test module compiled ok, but my test class couldn't be resolved.

I have lots of code in the same project that uses event emitter as both producers or consumers of events and I'm not experiencing similar issues.

Unfortunatelly I cannot provide a minimum repo, since this bug appears only in a specific case (but the same code fails on every machine) and I cannot give you the full code, because corporation would do some bad things to me.

Environment

I've used many minor versions of nest components, but always stick to major 6. Event emitter component was used in majors 0 and 1.
Currently I have:

"@nestjs-addons/in-memory-db": "^3.0.3",
"@nestjs/common": "^7.6.18",
"@nestjs/config": "^1.0.0",
"@nestjs/core": "^7.6.18",
"@nestjs/event-emitter": "1.0.0",
"@nestjs/platform-express": "^7.6.18",
"@nestjs/schedule": "^1.0.0",
"@nestjs/swagger": "^4.8.2",

Unfortunatelly I cannot provide a minimum repo, since this bug appears only in a specific case (but the same code fails on every machine) and I cannot give you the full code, because corporation would do some bad things to me.

We need a minimum reproduction repository. Otherwise, we won't be able to help.

@kamilmysliwiec yes, I understand. I'd kill such a bug request myself. However this issue is very hard to catch and I just cannot give you the code I have now.

I will try to create a new repo. Maybe I will look at the insides of emit method - that might give me some clues. I do not know how Nest internals work exactly. Is there a way that a method body declaration influences Nest dependency injection? Nothing else changes in my scenario (constructor, imports stay the same).

I don't think this is a bug in this package or in the framework itself but rather an issue with your project. That's why I've asked for the reproduction repository.

Yes, you were right. It was a problem on my side. There was a problem related to importing of dependencies, which resulted in DI engine going crazy.

Sorry to waste your time. Thank you for your help.

Take care.