[Recoil] Duplicate atom key 에러 +Next.js

moontag·2023년 1월 27일
2

에러

목록 보기
6/8

Next.js + Recoil 에러
(잘 동작은 되지만 콘솔에 경고메시지 출력됨)

버전

  • next - 13.1.1
  • recoil - 0.7.6

에러내용

  • atom key가 중복됐다는 에러
Expectation Violation: Duplicate atom key "atomKey". This is a FATAL ERROR in
      production. But it is safe to ignore this warning if it occurred because of
      hot module replacement.

원인

  • NextJS는 개발 중 파일변경되면 해당 파일을 다시 build함
  • build되면서 atom이 재선언됨
  • 그런데 atom key는 중복되지 않는 고유값을 가져야 하는데 재선언되면서 에러가 발생.

해결방법

  • 최상위폴더에서 .env 생성 ( Recoil 0.7.6 공식문서)
    • 주의 : key 중복검사를 비활성화하는 방식으로 우회하는 방법이다.
RECOIL_DUPLICATE_ATOM_KEY_CHECKING_ENABLED=false



참고
https://github.com/facebookexperimental/Recoil/issues/733

profile
터벅터벅 나의 개발 일상

0개의 댓글