Closed MeesEgberts closed 1 year ago
This is true because I inject a custom Prisma service into my services. The code that causes this is in the main.ts file because of the shutdown hook.
Hi @MeesEgberts are you using CustomPrismaModule
and CustomPrismaService
perhaps?
Here is an example how to enableShutdownHooks
for CustomPrismaService
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { CustomPrismaService } from 'nestjs-prisma';
import { extendedPrismaClient } from './prisma.extension';
async function bootstrap() {
const app = await NestFactory.create(AppModule);
const customPrismaService: CustomPrismaService<extendedPrismaClient> =
app.get('PrismaService');
await customPrismaService.enableShutdownHooks(app);
await app.listen(3000);
}
bootstrap();
Does this help you? I have update the extensions example too.
Might add that to the docs
@marcjulian I'm indeed using the ` but when I add your example to my
main.ts` I get the following error:
Nest could not find PrismaService element (this provider does not exist in the current context)
How do you registered your CustomPrismaModule
? Please provide an example, otherwise I cannot help.
The name
property for the CustomPrismaService
must be matching
// app.module.ts
import { Module } from '@nestjs/common';
import { CustomPrismaModule } from 'nestjs-prisma';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { extendedPrismaClient } from './prisma.extension';
@Module({
imports: [
CustomPrismaModule.forRootAsync({
name: 'PrismaService', // 👈 must be the same name here
useFactory: () => {
return extendedPrismaClient;
},
}),
],
controllers: [AppController],
providers: [AppService],
})
export class AppModule {}
// main.ts
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { CustomPrismaService } from 'nestjs-prisma';
import { extendedPrismaClient } from './prisma.extension';
async function bootstrap() {
const app = await NestFactory.create(AppModule);
const customPrismaService: CustomPrismaService<extendedPrismaClient> =
app.get('PrismaService'); // 👈 use the same name as in app.module.ts
await customPrismaService.enableShutdownHooks(app);
await app.listen(3000);
}
bootstrap();
Thanks! That solved my problem! I was using the wrong name for my service 😅
I will add this to the docs to clarify. CustomPrismaModule
is new so a bit more docs around it is needed.
when I remove the
PrismaService
from theapp.module.ts
the error message changes to:This is true because I inject a custom Prisma service into my services. The code that causes this is in the
main.ts
file because of the shutdown hook.This seems an essential part to me but whenever I remove these two lines the error is gone and it all seems to work! Yay! But I still need to figure out how to put this shutdown hook back without destroying my apps.