2.20) vercel에 프로젝트 배포 시 fetch failed 에러가 발생합니다
안녕하세요!
다름이 아니라 2.20 실습을 진행하면서 vercel에 앱을 배포하려고 하는데
Error: Command "npm run build" exited with 1
에러가 발생했습니다.
[cause]: Error: connect ECONNREFUSED 127.0.0.1:12345
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1607:16) {
errno: -111,
code: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 12345
}vercel 에서 에러 로그를 살펴보니 book/1, book/2, book/3 페이지를 prerendering 할 때 위와 같은 에러가 발생했습니다.
로컬에서 앱을 빌드한 후 실행했을 때엔 문제가 발생하지 않았습니다 ㅠㅠ
export default async function fetchBookById(id: number): Promise<BookData | null> {
const url = `http://127.0.0.1:12345/book/${id}`;
try {
const response = await fetch(url);
if (!response.ok) {
throw new Error();
}
return response.json();
} catch (error) {
console.error(error);
return null;
}
}위 코드는 book/{id}페이지로 들어왔을 때 실행하는 함수입니다!
import { useRouter } from "next/router";
import style from "./[id].module.css";
import fetchBookById from "@/lib/fetch-book-by-id";
import { GetStaticPropsContext, InferGetStaticPropsType } from "next";
import Head from "next/head";
export const getStaticPaths = () => {
return {
paths: [{ params: { id: "1" } }, { params: { id: "2" } }, { params: { id: "3" } }],
fallback: true,
};
};
export const getStaticProps = async (context: GetStaticPropsContext) => {
const id = context.params!.id;
const data = await fetchBookById(Number(id));
return {
props: {
data,
},
};
};
export default function Page({ data }: InferGetStaticPropsType<typeof getStaticProps>) {
const router = useRouter();
if (router.isFallback) {
return (
<>
<Head>
<title>한입북스</title>
<meta property="og:image" content="/thumbnail.png" />
<meta property="og:title" content="한입북스" />
<meta property="og:description" content="한입 북스에 등록된 도서들을 만나보세요" />
</Head>
<div>로딩중입니다.</div>
</>
);
}
if (!data) {
return {
notFound: true,
};
}
const { id, title, subTitle, author, coverImgUrl, description, publisher } = data;
return (
<>
<Head>
<title>{title}</title>
<meta property="og:image" content={coverImgUrl} />
<meta property="og:title" content={title} />
<meta property="og:description" content={description} />
</Head>
<div className={style.container}>
<div className={style.cover_img_container} style={{ backgroundImage: `url('${coverImgUrl}')` }}>
<img src={coverImgUrl} />
</div>
<div className={style.title}>{title}</div>
<div className={style.subTitle}>{subTitle}</div>
<div className={style.author}>
{author} | {publisher}
</div>
<div className={style.description}>{description}</div>
</div>
</>
);
}
혹시 몰라 해당 페이지의 전체 코드 같이 남겨봅니다 😭
감사합니다!
답변 1
0
안녕하세요 강혁준님 이정환입니다.
Vercel에 배포시 발생하는 해당 오류는 백엔드 서버의 배포가 이루어지지 않았기 때문에 발생하는 오류로
해당 챕터 영상의 7분 10초경 부터 오류의 원인을 설명드리고 해결하는 방법을 안내해드리고 있습니다.
해당 부분을 참고하시어 백엔드 서버를 배포한 다음 재 배포 해 보시면 될 것 같습니다.
감사합니다 😃
풀라우트캐시 동작 원리에서 데이터 캐시 관련 질문
0
22
2
next.js 프로젝트
0
27
1
Next.js + Tanstack Query BFF 구조 질문
0
29
2
Next.js 사전렌더링 이해하기 부분
0
33
2
모달 관련 질문
0
42
3
렌더링 관련 질문
0
80
2
중복으로 하나의 api를 요청할 때 캐싱 옵션 통일화
0
64
2
라우트 세그먼트 옵션 강좌 노트에 사소한 제보 남깁니다.
0
65
2
SSR시 context에 params말고 query를 사용하면 안되나요?
0
75
2
npx prisma db push 시 에러가 뜹니다.
0
94
3
vercel 배포를 실패하였습니다.
0
101
3
Image 컴포넌트 사용시 브라우저 콘솔에 경고는 왜 뜨는걸까요?
0
57
2
getServerSideProps 함수와 SSR의 관계
0
78
6
없는 페이지인데 풀라우트캐시로 저장이 되는 이유가 궁금합니다
0
61
2
실제 프로젝트에서 SSR 사용에 관해서 질문드립니다.
0
117
2
일반적인 nextjs project architecture에 대하여..
0
90
2
2.14 Search에서 작성한건 static이긴하지만 CSR이 아닌가요?
0
74
2
배포 시 오류 발생
0
90
2
백엔드 서버 오류납니다.
0
83
2
취약점 제거시 nestjs 버전 문제가 생길까요?
0
93
1
eslint.config.mjs 내 rules 어떻게 설정 하나요?
0
107
1
[book]/[id]/page.tsx 모달 띄울 때 성능 하락 현상은 ReviewList를 불러오면서 발생하는 문제 같습니다.
0
63
2
빨간줄 설정
0
77
2
익스텐션 질문
0
61
1





