Issues running Mikro-ORM with NestJS on Vercel platform
Describe the bug Trying to run a simple NestJS application with Mikro-ORM on Vercel platform.
Running/Building/Start dev on local environment doesn't have issues.
Stack trace
Neither EntityManager nor EntityRepository seems to be available as service when injecting into a Service class.
Tried with: constructor(@InjectRepository(Author) private readonly authorRepository: EntityRepository<Author>){}:
Error: Nest can't resolve dependencies of the AppService (?). Please make sure that the argument "AuthorRepository" at index [0] is available in the AppModule context.
Potential solutions:
- Is AppModule a valid NestJS module?
- If "AuthorRepository" is a provider, is it part of the current AppModule?
- If "AuthorRepository" is exported from a separate @Module, is that module imported within AppModule?
@Module({
imports: [ /* the Module containing "AuthorRepository" */ ]
})
Also tried with constructor(em: EntityManager) {}
Error: Nest can't resolve dependencies of the AppService (?). Please make sure that the argument SqlEntityManager at index [0] is available in the AppModule context.
Potential solutions:
- Is AppModule a valid NestJS module?
- If SqlEntityManager is a provider, is it part of the current AppModule?
- If SqlEntityManager is exported from a separate @Module, is that module imported within AppModule?
@Module({
imports: [ /* the Module containing SqlEntityManager */ ]
})
To Reproduce Reproductible repository is available here: https://github.com/emulienfou/template-nestjs-vercel
Expected behavior
NestJs should be able to load dependency EntityManager from driver.
This is currently not the case.
Injecting from import { EntityManager } from "@mikro-orm/core"; seems to resolve the issue temporarily.
However, due to injecting from @mikro-orm/core I need to do something like this:
const conn = em.getConnection() as AbstractSqlConnection;
const knex = conn.getKnex();
Preview https://template-nestjs-vercel-git-preview-beat-platform.vercel.app
Versions
| Dependency | Version |
|---|---|
| node | 20 |
| typescript | 5.4.2 |
| mikro-orm | 6.1.10 |
| postgresql driver | 6.1.10 |
| mikro-orm/nestjs | 5.2.3 |
| nestjs | 10.3.4 |
those problems are usually not about the place where you deploy to, but about dev vs production builds. have you tried to build your app for production and run it locally? i'd guess it will break the same