728x90
[Typescript] TS2307: Cannot find module '.png' or its corresponding type declarations.
React와 TypeScript를 사용하여 과제를 하던 중에 .png 확장자명을 가진 image파일을 import하려는데 자꾸 위와 같은 에러가 나면서 import가 되지 않았습니다. 검색해서 찾아보니 타입이 정의되어 있지 않아서라고 했습니다.
// tsconfig.json
...
"typeRoots": ["src/types"],
...
tsconfig.json 파일에 위와 같이 추가해주고
// src/types/images.d.ts
declare module '*.png';
declare module '*.jpg';
declare module '*.jpeg';
src/types 폴더에 위와 같이 .d.ts 파일을 추가하여 타입을 추가해주니 이미지를 정상적으로 import할 수 있었습니다.
아래의 글을 참고하여 에러를 해결했습니다.
Reference: https://egas.tistory.com/125
[Typescript] TS2307: Cannot find module '.png' or its corresponding type declarations.
webpack에서 이미지도 번들링 해주려고, 아래와 같이 설정을 해주니 typescript 쪽에서 해당 에러가 발생했다. // webpack.config.js ... { test: /\.(png|jpe?g)$/, use: { loader: 'file-loader', options: { n..
egas.tistory.com
반응형
'Studying Web Development > Free Memo' 카테고리의 다른 글
ES6에서 Arrow 함수를 언제, 왜 쓸까? (0) | 2022.06.22 |
---|---|
CORS에 대처하는 방법과 우회하는 방법 (0) | 2022.06.17 |
깨끗한 코드(Clean Code)를 위한 5가지 방법 (0) | 2022.06.16 |
var, let, const의 차이점 (0) | 2022.05.10 |
크롬 개발자도구에서 디버깅하는 방법 (debugger) (0) | 2021.09.05 |
댓글