반응형
Error occurred prerendering page "/api/generation". Read more: https://nextjs.org/docs/messages/prerender-error
import { NextRequest, NextResponse } from "next/server";
import { myApi, pokeApi } from "../instance";
import { GenerationI } from "@/interface/response";
export async function GET(request: NextRequest) {
const res = await pokeApi.get(`/generation`);
const data = res.data;
const count = data.count;
const results = await Promise.all(
Array.from({ length: count }, (_, index) => index + 1).map(async (item) => {
const genRes = await myApi.get<GenerationI>(`/generation/${item}`);
const genData = genRes.data;
return {
id: item,
name: genData.name,
pokemonCount: genData.pokemonCount,
pokemonIndexes: genData.pokemonIndexes,
};
})
);
return NextResponse.json(results);
}
대충 이런식으로 next js에서 app router를 이용하여 api를 개발하고 있었다
근데 왜인지 특정 경로 하나에서만 빌드에러와 배포에러가 뜨는 것이였다
vsc에 밑줄도 안쳐져서 npm run build 해보기 전까지는 발견도 못한 이슈..
아래는 빌드 오류와 함께 나온 로그 전문이다
더보기
Error occurred prerendering page "/api/generation". Read more: https://nextjs.org/docs/messages/prerender-error
AggregateError
at Z.from (/Users/guest1/Documents/seondal/PokemonQuiz/.next/server/chunks/688.js:22:23681)
at w.<anonymous> (/Users/guest1/Documents/seondal/PokemonQuiz/.next/server/chunks/688.js:24:9611)
at w.emit (node:events:518:28)
at x.<computed> (/Users/guest1/Documents/seondal/PokemonQuiz/.next/server/chunks/688.js:1:13285)
at ClientRequest.emit (node:events:518:28)
at Socket.socketErrorListener (node:_http_client:500:9)
at Socket.emit (node:events:518:28)
at emitErrorNT (node:internal/streams/destroy:169:8)
at emitErrorCloseNT (node:internal/streams/destroy:128:3)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
at aM.request (/Users/guest1/Documents/seondal/PokemonQuiz/.next/server/chunks/688.js:24:21578)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async /Users/guest1/Documents/seondal/PokemonQuiz/.next/server/app/api/generation/route.js:1:1029
at async Promise.all (index 0)
at async u (/Users/guest1/Documents/seondal/PokemonQuiz/.next/server/app/api/generation/route.js:1:956)
at async /Users/guest1/Documents/seondal/PokemonQuiz/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:6:42484
at async eI.execute (/Users/guest1/Documents/seondal/PokemonQuiz/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:6:32486)
at async eI.handle (/Users/guest1/Documents/seondal/PokemonQuiz/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:6:43737)
at async exportAppRoute (/Users/guest1/Documents/seondal/PokemonQuiz/node_modules/next/dist/export/routes/app-route.js:77:26)
✓ Generating static pages (8/8)
> Export encountered errors on following paths:
/api/generation/route: /api/generation
https://stackoverflow.com/questions/77511955/build-next-js-error-occurred-prerendering-page-api-user
결국 구글링 결과 찾아낸 해결법
export const dynamic = "force-dynamic";
문제가 생기는 파일 상단에 이 코드를 추가했더니 멀끔히 해결되었다.
다만 아직 다른 route.ts 파일은 전혀 문제가 없는데 왜 이 파일에서만 문제가 생긴건지 의문..
반응형
'_ > Velog' 카테고리의 다른 글
React Query와 Axios로 서버통신 쉽게하기 🌐 (0) | 2024.05.17 |
---|---|
[Github] 깃허브 Organization에서 Repository 핀이 안 될 때 해결방법 (0) | 2024.04.09 |
[SK Devocean] 데보션영 3기 합격 후기 🌊 (0) | 2024.03.06 |
next-auth로 카카오 소셜 로그인 5분만에 구현하기 👻 (0) | 2023.12.23 |
[React] Router 오류 (6.x.x 버전에서 바뀐 사용법) (0) | 2023.12.23 |