내가 겪은 이슈 #3.1 - tsconfig 덮어쓰기 이슈

불꽃남자·2020년 11월 1일
0

이것은 이전 글인 TS 컴파일 에러와 이어진다.

이전에 나는 tsc 명령어로 tsx파일을 컴파일했을 때 컴파일 결과 파일이 나오지 않아 이유를 탐색한 결과 tsconfig의 noEmit이 true로 설정되어 있어 일어난 일임을 알아냈었다.
근데 나는 noEmit: ture를 설정한 적이 없었는데, TS를 React에 적용하는 법을 알려주는 블로그에서 복사해서 붙여넣은 줄 알았다. 근데 아니었다.

react-scripts start 명령어를 사용할 때마다 tsconfig이 덮어씌워진다.

이게 문제였다. 내가 tsconfig을 임의로 설정해놓아도 react-scripts start 명령어를 사용할 때마다 아래의 tsconfig을 새로 만들어서 덮어씌워버린다.

{
  "compilerOptions": {
    "target": "es5",
    "module": "esnext",
    "jsx": "react",
    "strict": true,
    "noImplicitAny": false,
    "esModuleInterop": true,
    "skipLibCheck": true,
    "forceConsistentCasingInFileNames": true,
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ],
    "allowJs": true,
    "allowSyntheticDefaultImports": true,
    "noFallthroughCasesInSwitch": true,
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true
  },
  "include": [
    "src"
  ]
}

그리고 코드가 실행되면? App.js 파일을 찾지 못 하겠다며 오류를 반환한다. 자기네들이 "noEmit": true가 설정된 tsconfig을 덮어씌워놓고서는!!!

그래서 대체 왜 react-scripts start 명령어를 사용할 때마다 tsconfig이 덮어씌워지는지 이유를 탐색했다. 하지만 왜 이런 설정의 tsconfig이 덮어씌워지는지에 대한 이유는 찾아내지 못 했다. 하지만 해결방법은 찾아냈다.

@type/jest, @type/node 라이브러리를 추가할 것

@type/jest, @type/node 라이브러리를 추가했더니 실행이 되었다. 실행 당시의 package.json의 의존성은 다음과 같다.

{
  "name": "movie-app",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^5.11.4",
    "@testing-library/react": "^11.1.0",
    "@testing-library/user-event": "^12.1.10",
    "@types/jest": "^26.0.15",
    "@types/node": "^14.14.6",
    "@types/react": "^16.9.55",
    "@types/react-dom": "^16.9.9",
    "@types/styled-components": "^5.1.4",
    "axios": "^0.21.0",
    "dotenv": "^8.2.0",
    "react": "^17.0.1",
    "react-dom": "^17.0.1",
    "react-scripts": "4.0.0",
    "styled-components": "^5.2.0",
    "web-vitals": "^0.2.4"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest"
    ]
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },
  "proxy": "https://openapi.naver.com",
  "devDependencies": {
    "tsc-watch": "^4.2.9",
    "typescript": "^4.0.5"
  }
}
profile
프론트엔드 꿈나무, 탐구자.

0개의 댓글