본문 바로가기
Error 정리

TypeScript 사용하면서 겪은 Error 정리

by 집돌이디벨로퍼 2025. 9. 22.

첫번째

No inputs were found in config file 'c:/Users/mn846/OneDrive/Desktop/FishApp/server/tsconfig.json'. Specified 'include' paths were '["src/**/*"]' and 'exclude' paths were '["node_modules"]'.ts

 

==>

에러 원인 1: include, exclude 는 최상위 경로이기 때문에 compilerOptions 안으로 올수 없음

에러 원인 2 : src/**/* 구조가 아니면 안됨

에러 원인 3 : src/**/* 구조 안에 ts 파일이 없으면 안됨

 


두번째

 

const userRaw = { user.userName, password: hashedPassword, email }

user.userName 안되는 이유

==>

JS/TS에서 객체 리터럴을 만들 때는 항상 key: value 형태여야 함
user.userName  => 이건 문법적으로 잘못된 표현식

 

옳은 문법은 아래와 같다

const userRaw = {
                      userName: dto.userName,
                      nickname: dto.nickname,
                      password: hashedPassword,
                      email: dto.email
                    };

세번째

 

.env 환경변수 설정시 

==>

env 값은 string | undefined 타입이라 타입 단언(as string) 필요

   user: process.env.NAVER_USER as string,  // 네이버 아이디
   pass: process.env.NAVER_PASS as string,  // 네이버 비밀번호/앱 비밀번호

네번째

TypeScript에서 서드파티 라이브러리를 쓸 때는 보통 2개가 필요하다.. 이걸 이제알다니 헉..

두 가지..

  1. 실제 라이브러리 (runtime)
    • nodemailer
    • 실제 이메일을 보내는 기능이 구현된 코드
    • dependencies에 들어감 → 배포/실행 시에도 필요
     
  2. 타입 정의 (compile-time, 선택 사항)
    • @types/nodemailer
    • TypeScript가 nodemailer의 타입을 알 수 있게 해줌
    • devDependencies에 들어감 → 개발할 때만 필요

다섯번째 

절대경로, 상대적 경로

../../../.env  => 실행한 위치 기준 (상대적)

path.resolve(__dirname, "../../../.env") => 파일이 있는 위치 기준 (절대적)

상대적 경로보단 절대경로가 더 안정성 높음