Coding Planet

TS2307: Cannot find module '@prisma/client/runtime' or its corresponding type declarations. 본문

Nest.js

TS2307: Cannot find module '@prisma/client/runtime' or its corresponding type declarations.

jhj.sharon 2024. 7. 31. 11:13
반응형
import { ArgumentsHost, Catch, ExceptionFilter, HttpException } from '@nestjs/common';
import { PrismaClientKnownRequestError } from '@prisma/client/runtime/library';

@Catch()
export class PrismaClientExceptionFilter implements ExceptionFilter {
    catch(exception: unknown, host: ArgumentsHost) {
        const ctx = host.switchToHttp();
        const response = ctx.getResponse();
        const request = ctx.getRequest();

        let status = 500;
        let message = 'Internal server error';

        if (exception instanceof PrismaClientKnownRequestError) {
            if ((exception as PrismaClientKnownRequestError).code === 'P2002') {
                status = 409;
                message = 'Unique constraint failed on the fields: ' + (exception as PrismaClientKnownRequestError).meta?.target;
            } else {
                status = 400;
                message = (exception as PrismaClientKnownRequestError).message.replace(/\n/g, '');
            }
        } else if (exception instanceof HttpException) {
            status = exception.getStatus();
            message = exception.message;
        }

        response.status(status).json({
            statusCode: status,
            message,
            timestamp: new Date().toISOString(),
            path: request.url,
        });
    }
}

 

오류발생내역

 

  • TS2307: Cannot find module '@prisma/client/runtime' or its corresponding type declarations.
  • TS2339: Property 'code' does not exist on type 'unknown'

 

 

해결

import { PrismaClientKnownRequestError } from '@prisma/client/runtime/library';

 

 

Prisma 버전 변경: 최근 Prisma 버전에서 일부 내부 모듈의 경로가 변경되었음.

@prisma/client/runtime에서 @prisma/client/runtime/library로 변경!

반응형
Comments