• 카테고리

    질문 & 답변
  • 세부 분야

    백엔드

  • 해결 여부

    미해결

express 버전도 똑같은데 뭐가 문제인지 모르겠네요.

22.12.08 16:22 작성 조회수 170

0

HttpExceptionFilter 부분을 똑같이 적용해보고 있는데요.

import {
  ExceptionFilter,
  Catch,
  ArgumentsHost,
  HttpException,
} from '@nestjs/common';
import { Request, Response } from 'express';

@Catch(HttpException)
export class HttpExceptionFilter implements ExceptionFilter {
  catch(exception: HttpException, host: ArgumentsHost) {
    const ctx = host.switchToHttp();
    const response = ctx.getResponse<Response>();
    const httpStatus = exception.getStatus();
    response.status(httpStatus).json({});
  }
}

스크린샷 2022-12-08 오후 4.08.58.png제프로젝트에서는 위처럼 status를 찾지를 못하는데요.

실행자체는 되지만, package.json에 있는 버전들도 똑같이 맞췄는데도 왜 저럴까요??

node_modules 를 제거후 다시 npm i 로 설치해도 똑같습니다. ㅠㅠ

아래는 제 package.json 의 버전들 입니다.

"dependencies": {
    "@nestjs/common": "^8.0.0",
    "@nestjs/core": "^8.0.0",
    "@nestjs/platform-express": "^8.0.0",
    "@nestjs/typeorm": "^8.0.3",
    "mysql2": "^2.3.3",
    "reflect-metadata": "^0.1.13",
    "rimraf": "^3.0.2",
    "rxjs": "^7.5.5",
    "typeorm": "^0.2.45"
  },
  "devDependencies": {
    "@nestjs/cli": "^8.0.0",
    "@nestjs/schematics": "^8.0.0",
    "@nestjs/testing": "^8.0.0",
    "@types/express": "^4.17.13",
    "@types/jest": "27.4.1",
    "@types/node": "^16.0.0",
    "@types/supertest": "^2.0.11",
    "@typescript-eslint/eslint-plugin": "^5.0.0",
    "@typescript-eslint/parser": "^5.0.0",
    "eslint": "^8.0.1",
    "eslint-config-prettier": "^8.3.0",
    "eslint-plugin-prettier": "^4.0.0",
    "jest": "^27.2.5",
    "prettier": "^2.3.2",
    "source-map-support": "^0.5.20",
    "supertest": "^6.1.3",
    "ts-jest": "^27.0.3",
    "ts-loader": "^9.2.3",
    "ts-node": "^10.0.0",
    "tsconfig-paths": "^3.10.1",
    "typescript": "^4.3.5"
  },


사실 그냥 nest 새로 만든 프로젝트에 "http-exception.filter.ts" <- 해당 파일을 복붙만 해도 위처럼 빨간줄이 그어져서 response의 status를 찾지못하네요.

1. nest new project
2. 해당 프로젝트 src 폴더에 "http-exception.filter.ts " 복붙
3. status에 빨간줄 확인

위 빨간줄 무시하고 그냥 실행시켜도 문제없이 실행되긴합니다.
하지만, 그 원인을 알고싶네요! (또는 해결방법)

제 생각에는 제로초님의 node_modules 에 설치된것과 제가 가진 node_modules 에서 차이가 있을꺼같은데, 버전까지 동일하게 한 후 npm i 를 했는데도 이런경우에는 어떻게 해결해야하는지 질문드립니다!

답변 1

답변을 작성해보세요.

0

스크린샷 2022-12-08 오후 4.23.38.png제 vscode 툴에서 마우스 올렸을때 나오는 경고문구

속성 'status'가 'Response<any, Record<string, any>>'.ts(2339) 유형에 없습니다.

"@types/express-serve-static-core": "4.17.28"

이 버전을 설치하시면 에러가 나지 않을 겁니다. 현재 @types/express에서 사용하는 express-serve-static-core에 문제가 있네요.