본문 바로가기

교육

React : Cannot find type definition file for 'minimatch'. 오류

반응형

문제 원인
Cannot find type definition file for 'minimatch' 오류는 TypeScript가 minimatch 패키지의 타입 정의 파일을 찾을 수 없기 때문에 발생합니다. 이는 프로젝트에 해당 패키지의 타입 선언이 설치되지 않았거나, 타입 해석 과정에서 문제가 생겼을 때 나타납니다.

해결 방법
1. 타입 정의 패키지 설치
bash
npm install @types/minimatch --save-dev
2. 타입 경로 확인
tsconfig.json 파일에서 타입 해석과 관련된 설정을 점검하세요:

json
{
  "compilerOptions": {
    "typeRoots": [
      "./node_modules/@types",
      "src/types" // 필요시 추가
    ],
    // 기존 설정들 유지
    "target": "es5",
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ],
    "baseUrl": ".",
    "paths": {
      "@/*": ["src/*"]
    },
    "allowJs": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "noFallthroughCasesInSwitch": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "react-jsx"
  },
  "include": [
    "src"
  ]
}
3. 캐시 정리 후 재빌드
bash
# node_modules/.cache 제거
rm -rf node_modules/.cache

# TypeScript 캐시 제거
npx tsc --build --clean

# 다시 설치
npm install

# 다시 빌드
npm run build
4. package.json 확인
package.json에 minimatch가 명시적으로 포함되어 있는지 확인하고, 없다면 설치하세요:

bash
npm install minimatch
npm install @types/minimatch --save-dev
5. 불필요한 baseUrl 중복 제거
현재 tsconfig.json 파일에서 baseUrl이 두 번 정의되고 있습니다. 아래와 같이 수정하세요:

json
{
  "compilerOptions": {
    "target": "es5",
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ],
    "baseUrl": ".",  // 여기서만 설정
    "paths": {
      "@/*": ["src/*"]
    },
    "allowJs": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "noFallthroughCasesInSwitch": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "react-jsx"
  },
  "include": [
    "src"
  ]
}
이러한 단계를 거치면 minimatch 타입 정의 파일 관련 오류가 해결되어야 합니다.

반응형