Error Note/Resolved

Minified React error #130

πŸŒ³μ§€ν˜œμ˜ 숲 2023. 4. 26. 18:31

❓ λ°œμƒ μ—λŸ¬

ν”„λ‘œμ νŠΈ 진행쀑, 'react-nice-avatar'λ₯Ό ν™œμš©ν•΄λ³΄λ € ν•œλ‹€.

https://www.npmjs.com/package/react-nice-avatar

 

react-nice-avatar

react library for generating avatar. Latest version: 1.3.1, last published: 3 months ago. Start using react-nice-avatar in your project by running `npm i react-nice-avatar`. There are no other projects in the npm registry using react-nice-avatar.

www.npmjs.com

 

λ‘œμ»¬μ—μ„œλŠ” 아무 μ—λŸ¬μ—†μ΄ 잘 λ˜λŠ”λ°

λ‘œμ»¬ν™”λ©΄

 

λ°°ν¬νŽ˜μ΄μ§€μ—μ„œλŠ” μ•„λž˜μ™€ 같이 μ—λŸ¬λ©”μ„Έμ§€κ°€ λ‚˜μ˜€λ©΄μ„œ 화면이 먹톡이 됐닀.

λ°°ν¬νŽ˜μ΄μ§€ μ—λŸ¬λ©”μ„Έμ§€

 

ꡬ글링 ν•΄λ³΄λ‹ˆ, vite.config.ts에 μ•„λž˜μ™€ 같이 μ½”λ“œλ₯Ό μΆ”κ°€ν–ˆλŠ”λ°λ„ μ—λŸ¬κ°€ 사라지지 μ•Šμ•˜λ‹€.

vite.config.ts

 

ꡬ글링을 ν•΄λ³΄λ‹ˆ, λΉŒλ“œν–ˆμ„λ•Œ import의 문제인 것 κ°™μ•˜λ‹€.

μ°Έκ³ λΈ”λ‘œκ·Έ
https://velog.io/@merorii/Error-Minified-React-error-130-vite-%ED%8A%B9%EC%A0%95%EB%9D%BC%EC%9D%B4%EB%B8%8C%EB%9F%AC%EB%A6%AC-build-%EC%97%90%EB%9F%AC
 

Error: Minified React error #130 / vite + νŠΉμ •λΌμ΄λΈŒλŸ¬λ¦¬ build μ—λŸ¬

Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object.μ‚¬μš©ν•˜κ³ μžˆλŠ” λΌμ΄λΈŒλŸ¬λ¦¬κ°€ κ°μ²΄ν˜•μ‹

velog.io

 

μœ„ 글을 μ°Έκ³ ν•˜μ—¬

const GoodAvatar = Avatar.default ? Avatar.default : Avatar

을 ν•΄λ³΄λ‹ˆ defaultλΆ€λΆ„μ—μ„œ "'typeof ReactNiceAvatar'ν˜•μ‹μ— 'default'속성이 μ—†μŠ΅λ‹ˆλ‹€." 라고 λ©”μ„Έμ§€κ°€ λ‚˜μ˜€λŠ”λ°

이 뢀뢄을 κ°€λ¦¬ν‚€λŠ” 것 κ°™μ•˜λ‹€.

 

 

❗️ 원인

Avatar.defaultλ₯Ό μ‚¬μš©ν•΄μ•Όν•˜λŠ”λ° λΌμ΄λΈŒλŸ¬λ¦¬μ—μ„œ exportν•˜λŠ” Avatarμ—λŠ” defaultκ°€ μ—†μ–΄μ„œ 생긴 λ¬Έμ œμ˜€λ‹€.

λ”°λΌμ„œ νƒ€μž…μ„ μš°νšŒν•΄μ€˜μ•Όν•œλ‹€.

const AvatarAny: any = Avatar;
const GoodAvatar = AvatarAny.default || Avatar;

 

λ”°λΌμ„œ μ»΄ν¬λ„ŒνŠΈλ‘œλŠ” AvatarλŒ€μ‹  νƒ€μž…μ„ μš°νšŒν•œ GoodAvatarλ₯Ό μ‚¬μš©ν•˜λ©΄ λœλ‹€.