๐ŸšจError: Image with src "..." is missing required "width" property.๐Ÿšจ

ํ˜œํ˜œยท2023๋…„ 7์›” 24์ผ
0

Error Note

๋ชฉ๋ก ๋ณด๊ธฐ
4/19
post-custom-banner

โ— ๋ฌธ์ œ ๋‚ด์šฉ

Next.js 13 ๋ฒ„์ „์—์„œ Image ํƒœ๊ทธ๋ฅผ ์‚ฌ์šฉํ•  ๋•Œ ๋ฐœ์ƒํ•œ ์˜ค๋ฅ˜. Image ํƒœ๊ทธ์—๋Š” "width" ์†์„ฑ์ด ํ•„์š”ํ•œ๋ฐ, "width" ์†์„ฑ์ด ์—†๋‹ค๋Š” ๋‚ด์šฉ์ด ๋‚˜ํƒ€๋‚œ๋‹ค.
Next.js 13 ๋ฒ„์ „์˜ Image ํƒœ๊ทธ๋Š”, src, alt, width, height ์†์„ฑ์„ ํ•„์ˆ˜๋กœ ๊ฐ€์ ธ์•ผ ํ•˜๊ณ , fill ์†์„ฑ์„ ์‚ฌ์šฉํ•  ๋•Œ๋งŒ width, height๋ฅผ ์ƒ๋žตํ•  ์ˆ˜ ์žˆ๊ธฐ ๋•Œ๋ฌธ์—, ๊ทธ ์™ธ์˜ ๊ฒฝ์šฐ์—๋Š” width, height ๊ฐ’์„ ์ง€์ •ํ•ด ์ฃผ์–ด์•ผ ํ•œ๋‹ค. ๋‹ค๋ฅธ ํ•„์ˆ˜ ์†์„ฑ์ด ๋น ์กŒ์„ ๋•Œ๋„ ๊ฐ™์€ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ•œ๋‹ค.

โš’ ๋ฌธ์ œ ํ•ด๊ฒฐ

  const imageStyle = {
    width: '80vw',
    height: 'auto',
  };
...
    <Image
      src={imgSrc}
      alt="img_alt"
      width={800}
      height={800}
      style={imageStyle}
    />

ํ•˜์ง€๋งŒ ์ด๋•Œ px ๋‹จ์œ„์˜ number ๊ฐ’๋งŒ ์ง€์ •์ด ๊ฐ€๋Šฅํ•œ๋ฐ, ๋‚˜๋Š” vw ๋‹จ์œ„๋ฅผ ์‚ฌ์šฉํ•˜๊ณ  ์‹ถ์—ˆ๊ธฐ ๋•Œ๋ฌธ์— ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ–ˆ๋‹ค. ์ด ๊ฒฝ์šฐ์—๋Š” style ์†์„ฑ์„ ํ•จ๊ป˜ ์ง€์ •ํ•˜์—ฌ width, height ์†์„ฑ๊ฐ’ ๋“ฑ์„ ๋ฎ์–ด์“ธ ์ˆ˜ ์žˆ๋‹ค. width์™€ height ๊ฐ’์„ ์ ๋‹นํžˆ ์ง€์ •ํ•ด์ฃผ๊ณ , style ์†์„ฑ์œผ๋กœ ์›ํ•˜๋Š” ๊ฐ’์„ ๋„ฃ์–ด์ฃผ๋ฉด, px ์™ธ์˜ ๋‹ค๋ฅธ ๋‹จ์œ„๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด์„œ width์™€ height ๊ฐ’์„ ์ง€์ •ํ•  ์ˆ˜ ์žˆ๋‹ค.

๐Ÿ™‡โ€โ™‚๏ธ ์ฐธ๊ณ ์ž๋ฃŒ

Image Component

profile
์‰ฝ๊ฒŒ๋งŒ์‚ด์•„๊ฐ€๋ฉด์žฌ๋ฏธ์—†์–ด๋น™๊ณ 
post-custom-banner

1๊ฐœ์˜ ๋Œ“๊ธ€

comment-user-thumbnail
2023๋…„ 7์›” 24์ผ

์ข‹์€ ๊ธ€ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค.

๋‹ต๊ธ€ ๋‹ฌ๊ธฐ