해결된 질문
작성
·
385
·
수정됨
1
vercel에서 에러는
Failed to compile.
src/app/[location]/page.tsx
Type error: Type 'Props' does not satisfy the constraint 'PageProps'.
Types of property 'params' are incompatible.
Type '{ location: string; }' is missing the following properties from type 'Promise<any>': then, catch, finally, [Symbol.toStringTag]
Error: Command "npm run build" exited with 1
이며, 그전에도
Route "/[location]" used params.location
. params
should be awaited before using its properties. Learn more:
위와 같은 에러가 떴고, 이는 경로 및 쿼리 파라미터를 위한 객체에서 런타임 에러가 뜨는걸로 확인했습니다! 강의를 똑같이 따라갔는데, 위와 같은 에러가 나는게 의아하여 한번 문의드립니다!
import HomeButton from "../components/HomeButton";
import { getForecast } from "../utils/getForecast";
type Props = {
params: {
location: string;
};
searchParams: {
name: string;
};
};
export function generateMetadata({ searchParams }: Props) {
return {
title: `날씨 앱 - ${searchParams.name}`,
description: `${searchParams.name} 날씨를 알려드립니다`,
};
}
export default async function Detail({ params, searchParams }: Props) {
const name = searchParams.name;
const res = await getForecast(params.location);
return (
<>
<h1>{name}의 3일 예보</h1>
<ul>
{res.forecast.forecastday.map((day) => (
<li key={day.date}>
{day.date} / {day.day.avgtemp_c}
</li>
))}
</ul>
<HomeButton />
</>
);
}
크리스마스 쉬는날 연락드려, 죄송하며 빠른 답변 부탁드립니다!
공식문서를 참조해서 바꿨는데, 제 local에선 에러가 안뜨는데, 바꿀때마다 배포에 실패했습니다. 그러다가 params와 searchParams를 전부 Promise 타입으로 감싸고 await로 안전하게 접근하도록 수정했습니다.
바뀐 코드는 위와 같습니다! 한 2~3시간 꼼짝없이 매달렸네요.. 제 실력이 너무 부족했던 것 같습니다..! 다른 분들은, 저처럼 실수없이 잘 해결하시길!
일단 배포는 완료했습니다!