Next.js 15에서 params가 Promise로 바뀌면서 생기는 TypeError #375
Seon-K
started this conversation in
Trouble Shooting
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
🐞 문제 상황 (Problem Description)
app/activities/[id]/page.tsx에서params.id를 사용하려고 했지만 다음과 같이 작성한 코드에서 런타임 오류가 발생했습니다:에러를 해석해보자면,
params는Promise타입이어야 하는데,{ id: string }처럼 일반 객체로 줘서 생긴 오류입니다.💻 환경 정보 (Environment)
app/activities/[id]/page.tsx🔍 발생 원인 분석 (Investigation)
params가 Promise 형태로 변경되었습니다.params를 바로 구조 분해하려 하면 아직 resolve되지 않은 상태이므로undefined에러가 발생하게 됩니다.await로 비동기 처리하고, 타입도Promise<{ id: string }>로 선언해야 합니다.🛠 시도해본 해결 방법 (Attempts)
{ params }: { params: { id: string } }→const { id } = paramsawaitparams를 await 처리하여 비동기적으로 접근✅ 최종 해결 방법 (Final Solution)
💡 알게 된 점 (Lessons Learned)
params가Promise로 동작한다.params를 가지고 와야 한다.params를 사용할 때 무조건await처리해야 하며, 타입도Promise<{ id: string }>형태로 지정해줘야 한다.NEXT 공식 문서
Beta Was this translation helpful? Give feedback.
All reactions