nitro icon indicating copy to clipboard operation
nitro copied to clipboard

File uploads larger than 1 MiB crashes app

Open jtaavola opened this issue 2 weeks ago • 3 comments

Environment

nitro: 3.0.1-alpha.1 Vite: 7.2.7 Router / Start Version: 1.141.2

Reproduction

https://github.com/jtaavola/tanstack-start-file-upload-error

# success (file < 1 MiB)
curl -X POST http://localhost:3000/api/upload -F "file=@file_success.png"
# failure (file > 1 MiB)
curl -X POST http://localhost:3000/api/upload -F "file=@file_crash.png"

Describe the bug

Handling a file upload of a file larger an 1 MiB crashes the app with this error

TypeError: fetch failed
    at node:internal/deps/undici/undici:15422:13
    at async nitroDevMiddleware (file:///Users/jtaavola/software-development/projects/tanstack-start-file-upload-error/node_modules/.pnpm/[email protected][email protected][email protected][email protected]_@[email protected][email protected]__d47j3on5xijkh6qwgramligw7a/node_modules/nitro/dist/_build/vite.plugin.mjs:348:18) {
  [cause]: NotSupportedError: expect header not supported
      at processHeader (/Users/jtaavola/software-development/projects/tanstack-start-file-upload-error/node_modules/.pnpm/[email protected]/node_modules/undici/lib/core/request.js:406:11)
      at new Request (/Users/jtaavola/software-development/projects/tanstack-start-file-upload-error/node_modules/.pnpm/[email protected]/node_modules/undici/lib/core/request.js:187:11)
      at [dispatch] (/Users/jtaavola/software-development/projects/tanstack-start-file-upload-error/node_modules/.pnpm/[email protected]/node_modules/undici/lib/dispatcher/client.js:299:21)
      at Client.dispatch (/Users/jtaavola/software-development/projects/tanstack-start-file-upload-error/node_modules/.pnpm/[email protected]/node_modules/undici/lib/dispatcher/dispatcher-base.js:153:29)
      at [dispatch] (/Users/jtaavola/software-development/projects/tanstack-start-file-upload-error/node_modules/.pnpm/[email protected]/node_modules/undici/lib/dispatcher/pool-base.js:157:28)
      at Pool.dispatch (/Users/jtaavola/software-development/projects/tanstack-start-file-upload-error/node_modules/.pnpm/[email protected]/node_modules/undici/lib/dispatcher/dispatcher-base.js:153:29)
      at [dispatch] (/Users/jtaavola/software-development/projects/tanstack-start-file-upload-error/node_modules/.pnpm/[email protected]/node_modules/undici/lib/dispatcher/agent.js:122:23)
      at Agent.dispatch (/Users/jtaavola/software-development/projects/tanstack-start-file-upload-error/node_modules/.pnpm/[email protected]/node_modules/undici/lib/dispatcher/dispatcher-base.js:153:29)
      at node:internal/deps/undici/undici:11747:55
      at new Promise (<anonymous>) {
    code: 'UND_ERR_NOT_SUPPORTED'
  }
}

Additional context

I am handling the file upload in a TanStack Start server route

import { createFileRoute } from "@tanstack/react-router";
import { json } from "@tanstack/react-start";

export const Route = createFileRoute("/api/upload")({
    server: {
        handlers: {
            POST: async ({ request }) => {
                const formData = await request.formData();
                const file = formData.get("file");

                if (!file) {
                    return json(
                        { error: "Missing image field", code: "INVALID_REQUEST" },
                        { status: 400 },
                    );
                }

                if (!(file instanceof File)) {
                    return json(
                        { error: "Must be a file", code: "INVALID_REQUEST" },
                        { status: 400 },
                    );
                }

                // do stuff

                return json({
                    success: true,
                    message: "File uploaded successfully",
                });
            },
        },
    },
});

Logs


jtaavola avatar Dec 13 '25 01:12 jtaavola

🔗 Similar Issues

Related Issues

  • https://github.com/nitrojs/nitro/issues/3829
  • https://github.com/nitrojs/nitro/issues/3591
  • https://github.com/nitrojs/nitro/issues/3596
  • https://github.com/nitrojs/nitro/issues/3800
  • https://github.com/nitrojs/nitro/issues/3789

👤 Suggested Assignees


Enable issue planning

To enable issue planning, add the following to your .coderabbit.yaml:

issue_enrichment:
  planning:
    enabled: true

You can then request a plan by commenting @coderabbitai plan on any issue.

🧪 Issue enrichment is currently in early access.

To disable automatic issue enrichment, add the following to your .coderabbit.yaml:

issue_enrichment:
  auto_enrich:
    enabled: false

coderabbitai[bot] avatar Dec 13 '25 01:12 coderabbitai[bot]

Same error with npm:nitro-nightly@latest, although it doesn't crash the app anymore

jtaavola avatar Dec 13 '25 01:12 jtaavola

Thanks for repro. It is likely an issue with fetch snd unix socket issues we had similar issue before…

pi0 avatar Dec 13 '25 08:12 pi0