Search code examples
node.jstypescriptnestjsprisma

How to use Prisma Enum in Nest JS


I am using prisma with nestjs for my backend. I have written enum in prisma which is working correctly in debug mode. but when i generate prisma client along with nest build, I am getting error.

Object.values(client_1.RoomSharingType).join(', '),
                    ^
TypeError: Cannot convert undefined or null to object

the DTO, I am defining is:-

import {
  RoomSharingType,
} from '@prisma/client';

export class ValidationDemo {
  @IsEnum(RoomSharingType, {
    message:
      'OTP Type must be one of these values: ' +
      Object.values(RoomSharingType).join(', '),
  })
  @IsString()
  type: RoomSharingType;
}

Prisma Schema

enum RoomSharingType {
  TYPE1
  TYPE2
}

import

Everything is working in debug mode, but whenever i run build, i am getting the above error message.

The type generated by prisma client should work on nestjs end in production build file.


Solution

  • got the issue, i need to copy the prisma directory too and run prisma generate. I thought the build file contains all generated code.