-
-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MikroOrmModule.forRootAsync ignores MikroOrm provider useFactory function #12
Comments
Having |
You can see that from the stack trace, it is caused by that because nest di is trying to create new instance itself. Remove it and let the nest mikro orm adapter create the instance. |
Awesome! Removing MikroOrm from providers solved the problem, thanks for the support. |
Still seems to be an issue. You can find an example here https://github.com/marcus-sa/nest-convoy/blob/feat/mikro-orm/packages/messaging/broker/database/convoy-database.module.ts#L25 |
If you want help, provide a simple reproduction and all the details as described in issue template. Your linked project is too huge to review. But this particular issue was always invalid, if you see similar stack trace, it might point to some misusage rather than bug. Make sure you do not have |
I can still reproduce this issue with a similar setup, I dont have anything in providers/exports. Just trying to initialize with Here's the file I'm initializing the root module from, this is called only once by the AppModule entry point: import { Module } from '@nestjs/common';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { MikroOrmModule } from '@mikro-orm/nestjs';
@Module({
imports: [
MikroOrmModule.forRootAsync({
imports: [ConfigModule],
inject: [ConfigService],
useFactory: (configService: ConfigService) => ({
type: 'postgresql',
dbName: configService.get<string>('DATABASE_NAME'),
host: configService.get<string>('DATABASE_HOST'),
port: configService.get<number>('DATABASE_PORT'),
user: configService.get<string>('DATABASE_USER'),
password: configService.get<string>('DATABASE_PASS'),
entitiesTs: ['libs/entities/src/lib'],
autoLoadEntities: true,
}),
}),
]
})
export class DatabaseModule {} PS. Having the factory method async and return a promise yields the same result. |
I had the same error and I solved it by changing the type to drive
|
Describe the bug
When importing MikroOrm with
forRootAsync
and using Factory provider:useFactory
the given options are ignored and defaults are used instead.From the stack trace it looks like it is instantiating MikroOrm class directly instead of using
useFactory
from the MikroOrm custom provider that usesMikroOrm.init()
method.https://github.com/mikro-orm/nestjs/blob/master/src/mikro-orm.providers.ts#L24
But these are my suppositions and I feel I'm missing something.
Stack trace
To Reproduce
Simply use
MikroOrmModule.forRootAsync()
inimports[]
in Nestjs AppModule.In my case I'm injecting
ConfigService
from Nestjs, but i don't think this should change something.Expected behavior
Get a MikroOrm instance with provided configuration.
Versions
The text was updated successfully, but these errors were encountered: