πŸ’» DEV/ERROR & DEBUGGING

[NestJs] Parsing error: Cannot read file '.../tsconfig.json'.eslint

vodkassi 2022. 1. 9. 16:37
728x90

[ν˜„μƒ]

μƒˆλ‘œμš΄ NestJs ν”„λ‘œμ νŠΈλ₯Ό μƒμ„±ν–ˆμ„ λ•Œ, μ–΄λ–€ νŒŒμΌμ„ μ—΄λ“  "Parsing error: Cannot read file '.../tsconfig.json'.eslint" μ—λŸ¬κ°€ λ°œμƒν•¨. 

 

[μ‹œλ„ν•œ 방법과 κ²°κ³Ό]

tsconfig 파일 경둜λ₯Ό μ°ΎλŠ” λͺ¨λ“  λͺ…λ Ήμ–΄ λ˜λŠ” configuration 을 μƒλŒ€κ²½λ‘œμΈ ./tsconfig.json 둜 μˆ˜μ •ν•¨. μœ„μ˜ ν˜„μƒ μ—¬μ „νžˆ 동일함.

 

[원인]

.eslintrc.js 의 parserOptions λ‚΄ project 듀은 ν˜„μž¬ μž‘μ—… 경둜 (current working directory) 에 따라 μƒλŒ€μ μœΌλ‘œ ꡬ성됨. κ°€λ Ή, ν”„λ‘œμ νŠΈ κ²½λ‘œκ°€ μ•„λž˜μ™€ 같이 λ˜μ–΄ 있고 00.dev 폴더λ₯Ό root 으둜 ν•˜μ—¬ workspace λ₯Ό μ—΄κ²Œ 된 경우, ./tsconfig.json 은 곧 00.dev/tsconfig.json μ΄ λœλ‹€. ν•΄λ‹Ή κ²½λ‘œμ—λŠ” tsconfig.json 파일이 μ—†κΈ° 떄문에 parsing error κ°€ 뜨게 λœλ‹€. 

00.dev 
   |__project
   |	|_ eslintrc.js
   |	|_ tsconfig.json

 

[해결방법]

parserOptions 내에 tsconfigRootDir ν”Œλž˜κ·Έλ₯Ό μΆ”κ°€ν•˜μ—¬ tsconfig.json νŒŒμΌμ„ μ ˆλŒ€κ²½λ‘œμ—μ„œ 찾도둝 ν•΄μ€€λ‹€. 

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

 

[μ°Έκ³ ]