Skip to content

Next.js Build Fails with 400 Bad Request After 202 Pages When Using ky, Works with fetch #646

@MhL5

Description

@MhL5

I'm encountering an issue during the build process of my Next.js app. Everything works perfectly in development mode (next dev), but when I try to build the application (next build), I consistently get an error after successfully generating around 202 static pages.

The error occurs when using ky to fetch markdown files for blog posts. The first page that typically fails is page 202, with the error message showing a 400 Bad Request. However, when I switch to fetch for the same API call, the build completes successfully without any issues.

Error Log

HTTPError: Request failed with status code 400 Bad Request: GET http://blog.vsim.space/posts/markdown/2.md
    at o (D:\-code\work\vsim\.next\server\chunks\2576.js:1:82169)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async T._retry (D:\-code\work\vsim\.next\server\chunks\2576.js:1:85858)
    at async i.<computed> [as text] (D:\-code\work\vsim\.next\server\chunks\2576.js:1:82789)
    at async l (D:\-code\work\vsim\.next\server\app\[lang]\(with-navigation)\blog\page.js:1:17639)
    at async u (D:\-code\work\vsim\.next\server\app\[lang]\(with-navigation)\tips\[tipSlug]\page.js:1:6941)
Generating static pages (208/228)  [    ]
Error occurred prerendering page "/tr/tips/vsim-tip-code-delivery". Read more: https://nextjs.org/docs/messages/prerender-error

The issue arises when using ky:

const md = await ky
    .get(data.markdown_path, { cache: "no-store", timeout: 5 * 60 * 1000 })
    .text();

When I switch to fetch, the build succeeds without any issues:

const resMd = await fetch(data.markdown_path, { cache: "no-store" });
const md = await resMd.text();

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions