๋ชฉ์ฐจ (OPEN)
๐งฉ ๋ฌธ์ ์ํฉ
Vite + React + TypeScript ํ๊ฒฝ์์
.css๋ .png ํ์ผ์ import ํ๋๊น
์๋์ ๊ฐ์ ์๋ฌ๊ฐ ๋ฐ์ํ๋ค.
Cannot find module './style.css' or its corresponding type declarations.
Cannot find module './logo.png' or its corresponding type declarations.
์ฒ์์๋ ๊ทธ๋ฅ ๊ฒฝ๋ก ๋ฌธ์ ์ธ ์ค ์์๋๋ฐ,
์ค์ ์์ธ์ TypeScript๊ฐ ํด๋น ํ์ผ ํ์์
์ดํดํ์ง ๋ชปํด์ ์๊ธด ํ์ ์ค๋ฅ์์ ์๊ฒ ๋์๋ค.
๐ ํด๊ฒฐ ๋ฐฉ๋ฒ
์ง์ ํ์ ์ ์ธ ํ์ผ์ ๋ง๋ค์ด์
TypeScript์๊ฒ ์ด๋ฐ ํ์ผ๋ import ๊ฐ๋ฅํ๋ค๊ณ ์๋ ค์ค์ผ ํ๋ค.
// ๐ declarations.d.ts
// CSS ๋ชจ๋ ์ ์ธ
declare module '*.css' {
const content: { [className: string]: string };
export default content;
}
// ์ด๋ฏธ์ง ํ์ผ ์ ์ธ
declare module '*.png' {
const src: string;
export default src;
}
๊ทธ๋ฆฌ๊ณ tsconfig.json์๋ types ๊ฒฝ๋ก๊ฐ ์ ๋๋ก ํฌํจ๋์ด ์์ด์ผ ํ๋ค.
๋ณดํต์ include ํญ๋ชฉ์ "types" ๋๋ "types/*.d.ts"๋ฅผ ์ถ๊ฐํ๋ค๊ณ ํด์
์๋์ ๊ฐ์ด ํด์ฃผ์๋ค.
{
"include": ["src", "types"]
}
๐ก ๊ตํ
TypeScript๋ ๊ธฐ๋ณธ์ ์ผ๋ก .ts / .tsx ์ธ์ ๋ค๋ฅธ ํ์ผ ํ์ ์ ์ ์ ์๊ธฐ ๋๋ฌธ์
์ง์ ํ์ ์ ์ธ์ ํด์ค์ผ๋ง ์๋ฌ ์์ด ์ฌ์ฉ ๊ฐ๋ฅํ๋ค๋ ๊ฒ์ ์๊ฒ ๋์๋ค.
.css, .png, .svg ๋ฑ ์ ์ ์์์ ์ฌ์ฉํ๋ ํ๋ก์ ํธ์์๋
์ด๊ธฐ ์ธํ ์ declarations.d.ts ํ์ผ์ ๊ผญ ์ค๋นํด๋ฌ์ผ ๊ฒ ๋ค.
๐ ์ ์ฒด ์ฝ๋
๐ declarations.d.ts ์ ์ฒด ์ฝ๋

๐ tsconfig.json ์ ์ฒด ์ฝ๋

'๐ป ํ๋ก์ ํธ > ๐ ํธ๋ฌ๋ธ์ํ ' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
| [ํธ๋ฌ๋ธ์ํ ] ์ค์๊ฐ ์๋ฆผ ์ ์กํ๊ธฐ (1) | 2025.07.07 |
|---|---|
| [ํธ๋ฌ๋ธ์ํ ] Jest -> Vitest ๋ง์ด๊ทธ๋ ์ด์ ๋ฐฉ๋ฒ (0) | 2025.07.05 |
| [ํธ๋ฌ๋ธ์ํ ] NPM์์ PNPM์ผ๋ก (0) | 2025.06.04 |
| [ํธ๋ฌ๋ธ์ํ ] GitHub Actions์์ vite: not found ์ค๋ฅ ํด๊ฒฐ (0) | 2025.05.23 |