Giter Site home page Giter Site logo

Comments (7)

JhonFuenzalida avatar JhonFuenzalida commented on September 2, 2024 2

I had the same error and I solved it by changing the type to drive

import { Module } from '@nestjs/common';
  import { ConfigModule, ConfigService } from '@nestjs/config';
  import { MikroOrmModule } from '@mikro-orm/nestjs';
  import { PostgreSqlDriver } from '@mikro-orm/postgresql';
  
  @Module({
    imports: [
      MikroOrmModule.forRootAsync({
        imports: [ConfigModule],
        inject: [ConfigService],
        useFactory: (configService: ConfigService) => ({
          driver: PostgreSqlDriver,
          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 {}

from nestjs.

B4nan avatar B4nan commented on September 2, 2024 1

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.

from nestjs.

B4nan avatar B4nan commented on September 2, 2024

Having MikroORM explicitly inside providers seems wrong, try removing it.

from nestjs.

SimoneDagna avatar SimoneDagna commented on September 2, 2024

Awesome! Removing MikroOrm from providers solved the problem, thanks for the support.

from nestjs.

marcus-sa avatar marcus-sa commented on September 2, 2024

Still seems to be an issue.
Currently when instantiating using forRootAsync, it just causes the app to exit instantly, without any errors thrown at all.

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

from nestjs.

B4nan avatar B4nan commented on September 2, 2024

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 MikroORM inside providers, it will be exported automatically. Also ensure you are calling forRootAsync only once (but that wouldn't probably cause this).

from nestjs.

Saegusae avatar Saegusae commented on September 2, 2024

I can still reproduce this issue with a similar setup, I dont have anything in providers/exports. Just trying to initialize with forRootAsync will cause the same error even when PostgreSQLDriver is explicitly provided. Worth mentioning this is a NestJS application running under Nx Framework.

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.

from nestjs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.