ํ‹ฐ์Šคํ† ๋ฆฌ ๋ทฐ

๋ฌธ์ œ

ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ๋ฅผ ์‚ฌ์šฉํ•œ ํ”„๋กœ์ ํŠธ ๋‚ด์—์„œ svg ํŒŒ์ผ์„ ์ปดํฌ๋„ŒํŠธ๋กœ์„œ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•ด ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•˜์˜€๋‹ค.

import { ReactComponent as ProfileIcon } from '/images/icon-profile.svg';

ํ•˜์ง€๋งŒ ํ•ด๋‹น ์ฝ”๋“œ์—์„œ ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ•˜์˜€๋‹ค.

"*.svg"' ๋ชจ๋“ˆ์— ๋‚ด๋ณด๋‚ธ ๋ฉค๋ฒ„ 'ReactComponent'์ด(๊ฐ€) ์—†์Šต๋‹ˆ๋‹ค.

 

๋ฌธ์ œ ํ•ด๊ฒฐ

์Šคํƒ์˜ค๋ฒ„ํ”Œ๋กœ์šฐ์—์„œ ๋‚˜์™€ ๊ฐ™์€ ๋ฌธ์ œ๋ฅผ ๋ฐœ๊ฒฌํ•˜์˜€๊ณ  ํ•ด๋‹น ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ์—ˆ๋‹ค.https://stackoverflow.com/questions/54121536/typescript-module-svg-has-no-exported-member-reactcomponent

 

TypeScript - Module '"*.svg"' has no exported member 'ReactComponent

I'm trying to import an .svg file as a React component with TypeScript. According to the React docs, this is done like so: import { ReactComponent as Icon } from './Icon.svg'; Following the

stackoverflow.com

custom.d.ts ํŒŒ์ผ์„ ์ƒ์„ฑํ•ด์ฃผ๊ณ  ํ•ด๋‹น ํŒŒ์ผ ๋‚ด์—์„œ ๋ชจ๋“  svg ํŒŒ์ผ์— ๋Œ€ํ•ด ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์†์„ฑ์„ ์„ค์ •ํ•ด ์ฃผ์—ˆ๋‹ค.

declare module '*.svg' {
    import React = require('react');
    export const ReactComponent: React.FC<React.SVGProps<SVGSVGElement>>;
    const src: string;
    export default src;
  }

๋˜ํ•œ ts ์ปดํŒŒ์ผ๋Ÿฌ๊ฐ€ ts|tsx ํ™•์žฅ์„ ์ฒ˜๋ฆฌํ•˜๋„๋ก tsconfig.json์— custom.d.ts๋ฅผ ํ˜ธ์ถœํ•˜๋„๋ก ํ•ด์ฃผ์–ด ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•˜์˜€๋‹ค. 

{
  "compilerOptions": {
  
  ( ... )
   
  "include": [
    "next-env.d.ts",
    "**/*.ts",
    "**/*.tsx",
    "next.config.js",
    "custom.d.ts",
    "styles",
    "pages",
    "public"
  ],
  
 ( ... )
}
๋Œ“๊ธ€
๊ณต์ง€์‚ฌํ•ญ
์ตœ๊ทผ์— ์˜ฌ๋ผ์˜จ ๊ธ€
์ตœ๊ทผ์— ๋‹ฌ๋ฆฐ ๋Œ“๊ธ€
Total
Today
Yesterday
๋งํฌ
TAG
more
ยซ   2024/07   ยป
์ผ ์›” ํ™” ์ˆ˜ ๋ชฉ ๊ธˆ ํ† 
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31
๊ธ€ ๋ณด๊ด€ํ•จ