Giter Site home page Giter Site logo

Comments (5)

MeesEgberts avatar MeesEgberts commented on June 2, 2024 1

Thanks! That solved my problem! I was using the wrong name for my service 😅

from nestjs-prisma.

marcjulian avatar marcjulian commented on June 2, 2024

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

from nestjs-prisma.

MeesEgberts avatar MeesEgberts commented on June 2, 2024

@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)

from nestjs-prisma.

marcjulian avatar marcjulian commented on June 2, 2024

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();

from nestjs-prisma.

marcjulian avatar marcjulian commented on June 2, 2024

I will add this to the docs to clarify. CustomPrismaModule is new so a bit more docs around it is needed.

from nestjs-prisma.

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.