NestJS 시작부터 골때리는 파싱에러 해결법

캡틴 노드랭크·2021년 9월 7일
0

NestJS

목록 보기
1/5
post-thumbnail

NestJS 간단히 소개

NodeJS의 떠오르는 프레임워크이다.

TypeScript를 지원하고 있으며, 순수 JavaScript도 지원하지만, 해석을 위해 트랜스 파일러인 Babel을 필요로 한다.

TIP!

트랜스파일러란 무엇이며? 왜 쓰이는 걸까?
트랜스 파일러(TransPiler)는 소스대 소스 컴파일러라고 하며, 한 프로그래밍 언어로 작성된 소스코드를 읽고 다른 언어로 동등한 코드를 생성하는 도구이다.
대표적으로 Babel과 정적의 타입을 가진 TypeScript 등이 있다.

NestJS 시작하기

공식 페이지에서 NestJS 프로젝트를 시작하는 명령어이다.

npm i -g @nestjs/cli
nest new project-name

문제의 파싱 에러

위 경로의 tsconfig.json에서 elint를 전혀 해석하지 못하고있다.

.eslintrc.js파일을 찾아서 parserOptions에 다음 부분을 추가해준다.

  parserOptions: {
    project: 'tsconfig.json',
    tsconfigRootDir: __dirname,
    sourceType: 'module',
  },

그리고 껐다키면 잘된다.

그렇다면 왜 저런 Parsing 오류가 발생하는걸까?

StackOverflow에서 나온 답변은 다음과 같다.

By default, the projects (in parserOptions) are resolved relative to the current working directory. 
If you run eslint in a different working directory to the folder containing tsconfig.json, 
 @typescript-eslint/parser will not be able to locate the file.

To fix this, you can set tsconfigRootDir to __dirname, 
  which would make the parser resolve the project configuration relative to .eslintrc.js:

기본적으로 프로젝트(parserOptions 포함)는 현재 작업 디렉토리를 기준으로 확인됩니다. tsconfig.json이 포함된 폴더와 다른 작업 디렉터리에서 eslint를 실행하면 @typescript-eslint/parser가 파일을 찾을 수 없습니다.

라고 한다.

아무래도 Git Repository에서 클론해온 루트 폴더 내에 package.json이 존재하고, 하필이면 거기다 또 NestJS프로젝트를 생성했기 때문에.. 루트 디렉토리를 현재의 디렉토리 기준으로 잡았다.

package.jsonnodeModule폴더를 싹 지우면 문제 없고, 만약 필요하다면 아래의 속성을 추가해주면 된다.

  parserOptions: {
    project: 'tsconfig.json',
    tsconfigRootDir: __dirname,
    sourceType: 'module',
  },

tsconfigRootDir: __dirname,

꼭 추가하자.

ref: NestJS, 벨로그 NestJS 파싱오류 해결하기,스택오버플로우 파싱오류 해결

profile
다시 처음부터 천천히... 급할필요가 없다.

0개의 댓글