Closed rychkog closed 6 years ago
Hi @rychkog, Let's try to export entire providers objects, for example:
exports: [{
provide: 'PhotoRepositoryToken2',
useFactory: (connection: Connection) => connection.getRepository(Photo2),
inject: ['DbConnectionToken'],
}],
To avoid repeating you can create a standalone variable.
@kamilmysliwiec Now it works like that in the example project but doesn't in my actual project... At the point where there is an import statement for the main Nest module, it just exists node process
At this point node process exits. I am totally confused ...
import { ApplicationModule } from './modules/app.module';
There are no errors at all
@rychkog we need more context here, please, attach some code. Also, let's try to disable modules step by steps so you won't have to paste everything here :)
@kamilmysliwiec I understand - trying to come up with a more descriptive example
@rychkog awesome 🙂
@kamilmysliwiec Good morning! :) I've spent whole evening yesterday trying to figure out what is the cause of my issue, so I describe it here in hope, that community might benefit from my pain and foolishness :)
Symptoms:
provide
of undefined
.Solutions and observations
for issue#1
Your suggestion about having in exports
entire provider object helped.
But occasionally I had an issue that sounded like "cannot access property provide
of undefined
". Debugging revealed that dependencies array gets extracted by Reflect from exports
section occasionally contained undefined as one of the values. Maybe this is connected but your workaround helped and I haven't seen this error since then.
for issue#2 This one weird and old as the Universe - circular dependency :)
I had a RepositoryModule
, that contained a class like this
export class DatabaseObject {
@PrimaryGeneratedColumn()
id: number;
....
}
This class, in turn, was used by another class
export class MySuperClass extends DatabaseObject {
...
}
and this class was imported in RepositoryModule
(just stop here and behold the Cycle:) ) for new repository object creation. :)
Once I've extracted DatabaseObject
from the module issue gets resolved
Thanks for your support! :)
Hi @rychkog, True, the circular dependencies may cause dizziness 🙂 Thank you for your comprehensive explanation!
I had this issue too. Removing a barrel file for repositories (./repositories/index.ts
) and reimporting from the files directly solved similar problem with imported item being undefined
.
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Hi @kamilmysliwiec!
I'm currently building a project using Nest and TypeORM. But I've been experiencing a strange issue with a broken DI mechanism. It looks to me that it is somehow connected to the Nest <-> TypeORM wiring Here is the screenshot of my terminal's output
Below is the branch of my Nest fork, where this issue is reproducible (based on examples/05-sql-typeorm). https://github.com/nestjs/nest/compare/master...rychkog:typeorm-nest-di-resolver-issue
Brief description: when I start creating a module that contains couple repositories as providers and connection for them - DI gets broken and gives me a message that you can see on the screenshot above.
If you'll have any questions regarding the issue - feel free to contact me - I'll try to help as much as I can