Skip to content

"TypeError: fetch failed" in production but not preview #15011

@siddharth-narayan

Description

@siddharth-narayan

Describe the bug

I'm getting this error

[500] GET /blog
TypeError: fetch failed
    at node:internal/deps/undici/undici:14900:13
    at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
    at async fetch (file:///home/siddharth/projects/personal-site/build/server/index.js:7374:18)

When fetching, but only in a production build. In the preview version it works perfectly.

Here's what my directory tree looks like

[nix-shell:~/projects/personal-site]$ tree -I 'node_modules|build' -L 4
.
├── package.json
├── package-lock.json
├── src
│   ├── app.d.ts
│   ├── app.html
│   ├── lib
│   │   └── index.ts
│   └── routes
│       ├── +layout.svelte
│       ├── +page.svelte
│       └── [...slug]
│           ├── +page.svelte
│           └── +page.ts
├── static
│   ├── build
│   │   ├── blog
│   │   │   └── blog-post.html
│   │   ├── blog.html
│   │   └── index.html
│   └── favicon.png
├── svelte.config.js
├── tsconfig.json
└── vite.config.ts

And importantly, src/routes/[...slug]/+page.ts contains

import { error } from "@sveltejs/kit"


// Uses the correct fetch
export async function load({ fetch, params, url }) {
    let slug = params.slug
    if (!slug) {
        slug = "index"
    }

    // Catch any /build paths not in /static
    if (url.pathname.startsWith("/build")) {
        return error(404)
    }

    let response = await fetch('/build/' + params.slug + '.html')
    if (!response.ok) {
        return
    }

    let html = await response.text()
    return { html: html }
}

My understanding is that the client will always request the page from the server, because I have data-sveltekit-reload set in app.html
Then the server, running load attempts to fetch /build/blog.html and for some reason fails.

Reproduction

The repro can be found at https://github.com/siddharth-narayan/personal-site/tree/repro -- A stripped down version of my project that I feel contains the bare minimum to reproduce. All that's needed should be an npm install and then either npm run build && node build or npm run preview

Logs

System Info

System:
    OS: Linux 6.12 cpe:/o:nixos:nixos:25.11 25.11 (Xantusia)
    CPU: (8) x64 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz
    Memory: 23.86 GB / 31.14 GB
    Container: Yes
    Shell: 5.3.3 - /nix/store/35yc81pz0q5yba14lxhn5r3jx5yg6c3l-bash-interactive-5.3p3/bin/bash
  Binaries:
    Node: 22.21.1 - /nix/store/l85fis49agvp5q1ild1rfh4rrgmn92sr-nodejs-22.21.1/bin/node
    npm: 10.9.4 - /nix/store/l85fis49agvp5q1ild1rfh4rrgmn92sr-nodejs-22.21.1/bin/npm
  Browsers:
    Chromium: 142.0.7444.175
    Firefox: 145.0.2
    Firefox Developer Edition: 145.0.2
  npmPackages:
    @sveltejs/adapter-auto: ^3.0.0 => 3.3.1 
    @sveltejs/adapter-node: ^5.0.0 => 5.4.0 
    @sveltejs/kit: ^2.0.0 => 2.48.4 
    @sveltejs/vite-plugin-svelte: ^6.0.0 => 6.2.1 
    svelte: ^5.0.0 => 5.43.6 
    vite: ^7.0.0 => 7.2.2

Severity

serious, but I can work around it -- I can't serve a fully built version of my personal site, I have to serve the preview version

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions