skip to Main Content

i am new in typescript, when i try to run my docker-compose up command, i am getting this error, i am using es7

TypeError: Class constructor PrismaClient cannot be invoked without 'new'

can anyone please help me why i am getting this error ? any help will be really appreciated, here i have added my code for it,

import { Injectable, OnInit, OnDestroy } from "@tsed/di";
import { PrismaClient } from "@prisma/client";

@Injectable()
export class PrismaService extends PrismaClient implements OnInit, OnDestroy {
  async $onInit() {
    await this.$connect();
  }

  async $onDestroy() {
    await this.$disconnect();
  }
}

2

Answers


  1. change in tsconfig file

    {
        "compilerOptions": {
            "target": "ES6",
            ...
        }
    }
    
    Login or Signup to reply.
  2. Out prisma.service.ts looks like this:

    import { INestApplication, Injectable, OnModuleInit } from '@nestjs/common';
    import { Prisma, PrismaClient } from '@prisma/client';
    
    import { LoggerService } from '@common/providers/logger';
    
    interface LogOptions extends Prisma.PrismaClientOptions {
        log: [
            {
                emit: 'event';
                level: 'query';
            }
        ];
    }
    
    @Injectable()
    export class PrismaService extends PrismaClient<LogOptions> implements OnModuleInit {
        constructor(private logger: LoggerService) {
            super({
                log: [
                    {
                        emit: 'event',
                        level: 'query'
                    }
                ]
            });
    
            this.logger.setContext(PrismaService.name);
        }
    
        async onModuleInit() {
            await this.$connect();
        }
    
        async enableShutdownHooks(app: INestApplication) {
            this.$on('beforeExit', async () => {
                await app.close();
            });
        }
    }
    

    And in tsconfig.json we have the following:

        "compilerOptions": {
            "module": "CommonJS",
    ...
            "target": "es2019",
    ...
        },
    

    Hope this helps.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search