์ฝ”๋”ฉ ๋ฉ”๋ชจ

Parsing error: Cannot read file '...tsconfig\file' ํ•ด๊ฒฐ ๋ฐฉ๋ฒ•

fairy_taIe 2023. 5. 18. 21:16

Parsing error: Cannot Read File ...tsconfig.json

๋ชจ๋“  ํŒŒ์ผ ์ƒ๋‹จ์— ๋“ฑ์žฅํ•œ ํŒŒ์ผ ์—๋Ÿฌ..

๋”ฐ๋ผ์„œ eslint์ƒ์—์„œ ๋ฐœ์ƒํ•œ ์—๋Ÿฌ์ด๋ฉฐ, ํ•ด๋‹น ํŒŒ์ผ์˜ ๊ฒฝ๋กœ๋ฅผ ์ถ”๊ฐ€ํ•ด์คŒ์œผ๋กœ์จ ์ œ๋Œ€๋กœ ๋œ ํŒŒ์ผ ๊ฒฝ๋กœ๋ฅผ ์ฐพ๋„๋ก ํ•ด์•ผ ํ–ˆ๋‹ค.

๐Ÿ”Ž ํ•ด๊ฒฐ ๋ฐฉ๋ฒ• 1

ํ•ด๊ฒฐ๋ฐฉ๋ฒ•
.eslintrc.js ํŒŒ์ผ์—์„œ ์•„๋ž˜ ๋‚ด์šฉ์„ ์ถ”๊ฐ€ํ•ด ์ฃผ๋ฉด ๋œ๋‹ค.

overrides: [
    {
      files: ['*.ts', '*.tsx'],
      rules: {
        'no-unused-vars': 'off',
        '@typescript-eslint/no-unused-vars': ['error'],
        '@typescript-eslint/no-shadow': ['error'],
        'no-shadow': 'off',
        'no-undef': 'off',
      },
      //์ด ๋ถ€๋ถ„์„ ์ถ”๊ฐ€์ฃผ์ž!
      parserOptions: {
        project: ['tsconfig.json'],
        createDefaultProgram: true,
      },
    },
  ],

๊ตฌ๊ธ€๋ง์œผ๋กœ ๋“œ๋””์–ด ํ•ด๊ฒฐ๋˜์—ˆ๋‹ค.. ๊ตฌ๊ธ€์—†์ด ๋ชป ์‚ด์•„

++ ๊ทผ๋ฐ ๋˜ ๊ณ„์† ์ด ์ƒํ™ฉ์ด ๊ณ„์† ๋˜์—ˆ๋‹ค ใ… .ใ… 
๊ทธ๋ž˜์„œ ์ฐพ์•„๋ณด๋‹ˆ
extends์— @typescript-eslint/parser๋ฅผ ๋„ฃ์œผ๋‹ˆ ํ•ด๊ฒฐ์ด ๋œ๋‹ค๊ณ ...

๊ทธ๋ž˜์„œ ๊ฒฐ๋ก ์€ (๋‚ด ํŒŒ์ผ ์ž‘์—…ํ™˜๊ฒฝ์ผ ๋ฟ)

{
   "root": true,
   "extends": [
       "eslint:recommended",
       "plugin:@typescript-eslint/recommended",
       "plugin:@typescript-eslint/parser" // ์—ฌ๊ธฐ
   ],
   "parser": "@typescript-eslint/parser",
   "parserOptions": { // ์—ฌ๊ธฐ
       "project": ["tsconfig.json"],
       "createDefaultProgram": true
   },
   "plugins": ["@typescript-eslint"],
   "rules": {
       "@typescript-eslint/strict-boolean-expressions": [
           2,
           {
               "allowString": false,
               "allowNumber": false
           }
       ]
   },
   "ignorePatterns": ["src/**/*.test.ts", "src/frontend/generated/*"]
}

๐Ÿ’ก ํ•ด๊ฒฐ ๋ฐฉ๋ฒ• 2

์ด๊ฑธ๋กœ ํ•ด๊ฒฐ ๋ด„!!!!!!!

  • ์›์ธ
    .eslintrc.js ์˜ parserOptions ๋‚ด project ๋“ค์€ ํ˜„์žฌ ์ž‘์—… ๊ฒฝ๋กœ์— ๋”ฐ๋ผ ์ƒ๋Œ€์ ์œผ๋กœ ๊ตฌ์„ฑ๋จ.
    ํ”„๋กœ์ ํŠธ ๊ฒฝ๋กœ๊ฐ€ ์•„๋ž˜์™€ ๊ฐ™์ด ๋˜์–ด ์žˆ๊ณ  00.dev ํด๋”๋ฅผ root ์œผ๋กœ ํ•˜์—ฌ workspace ๋ฅผ ์—ด๊ฒŒ ๋œ ๊ฒฝ์šฐ, ./tsconfig.json ์€ ๊ณง 00.dev/tsconfig.json ์ด ๋œ๋‹ค. ํ•ด๋‹น ๊ฒฝ๋กœ์—๋Š” tsconfig.json ํŒŒ์ผ์ด ์—†๊ธฐ ๋–„๋ฌธ์— parsing error ๊ฐ€ ๋œจ๊ฒŒ ๋œ๋‹ค.

parserOptions ๋‚ด์— tsconfigRootDir ํ”Œ๋ž˜๊ทธ๋ฅผ ์ถ”๊ฐ€ํ•˜์—ฌ tsconfig.json ํŒŒ์ผ์„ ์ ˆ๋Œ€๊ฒฝ๋กœ์—์„œ ์ฐพ๋„๋ก ํ•ด์ค€๋‹ค.

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

๊ทธ๋ฆฌ๊ณ 

tsconfig.eslint.json ์— ์•„๋ž˜ ์ฝ”๋“œ ์‚ฝ์ž…

{
  "extends": "./tsconfig.json",
  "include": [
    // ๐Ÿ‘‡๏ธ add all the directories and files
    // that you want to lint here
    "src",
    "tests",

    // add all files in which you see
    // the "parserOptions.project" error
    ".eslintrc.js"
  ]
}