[react-native | 에러] import hexToRgb from './hexToRgb';

주연쓰·2022년 12월 15일
0
  • react-native-custom-switch 라이브러리를 사용하던 도중 발생한 에러

  • hexToRgb를 제대로 import 하지 못했을 때 뜸

에러 전문:

iOS Bundling failed 16570ms
Unable to resolve "./hexToRgb" from "node_modules\react-native-custom-switch\src\customSwitch.js"

import hexToRgb from './hexToRgb'; 에러 해결법

1.

검색했을 때 hex-rgb 라이브러리가 있길래 해봤는데, hexToRgb가 아니어서 이 방법은 아니었음 ->

다음 명령어로 라이브러리를 install 해준다

npm install hex-rgb

2.

다시 한번 에러와 에러난 파일을 읽어보니 "hexToRgb" 가 react-native-custom-switch 파일 내에서 불러오는, 커스텀 된 함수였음

해당 함수는 같은 레벨의 폴더 안의 utils.js 파일 안에 있었음

그러나 아무리 파일명을 바꿔도 계속 경고가 뜨고,,,

파일을 더 뒤져보니 아래쪽에
LayoutAnimation.Types.spring 이 LayoutAnimation.Types.Spring 으로 s가 대문자로 오류가 나 있었음!!
이거 고치니까 파일경로는 이렇게 놔둬도 잘 작동되더라구요 (import hexToRgb from "./utils";)

결론 : 파일경로가 아니라 오타 하나가 문제였다^^

원본 파일에서 고친 것 :
customSwitch.js 파일에서

import hexToRgb from "./utils";

....

          LayoutAnimation.Types.spring,

끝!
덕분에 라이브러리 파일들을 자세히 살펴보고 이해할 수 있는 기회가 되어서 좋았다

profile
( •̀ ω •́ )✧

0개의 댓글