Skip to content

Content-Type header not automatically set with FormData + Request on Node 24 #8845

@rossipedia

Description

@rossipedia

Describe the bug

On Node v24, when passing a FormData instance as the body of a Request, the standard behavior is that the Content-Type header is automatically set to multipart/form-data (with diver) unless explicitly set by the Request constructor's init param.

However, this does not seem to be the case in the jsdom environment. Instead, an error is thrown if you attempt to consume the Request instance using Request.prototype.formData()

Note

This issue is not present (per my testing) on Node versions prior to 24

Reproduction

https://github.com/rossipedia/vitest-formdata-jsdom-issue

The following test file will demonstrate the issue:

// @vitest-environment jsdom
import { test, expect } from "vitest";

test("foo", async () => {
  const formData = new FormData();
  formData.set("foo", "bar");

  const req = new Request("http://localhost:3000/", {
    method: "POST",
    body: formData,
  });

  await expect(req.formData()).resolves.toBeInstanceOf(FormData);
});

This test would be expected to pass, however instead it fails with the error:

TypeError: Content-Type was not one of "multipart/form-data" or "application/x-www-form-urlencoded".

System Info

System:
    OS: macOS 26.0.1
    CPU: (16) arm64 Apple M4 Max
    Memory: 23.17 GB / 64.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 24.10.0 - /Users/bryanross/.local/state/fnm_multishells/47943_1761602626870/bin/node
    Yarn: 1.22.22 - /Users/bryanross/.local/state/fnm_multishells/47943_1761602626870/bin/yarn
    npm: 11.6.1 - /Users/bryanross/.local/state/fnm_multishells/47943_1761602626870/bin/npm
    pnpm: 10.18.1 - /Users/bryanross/.local/state/fnm_multishells/47943_1761602626870/bin/pnpm
    bun: 1.3.1 - /opt/homebrew/bin/bun
    Deno: 2.5.4 - /opt/homebrew/bin/deno
  Browsers:
    Chrome: 141.0.7390.123
    Firefox: 143.0.3
    Safari: 26.0.1
  npmPackages:
    vitest: ^4.0.3 => 4.0.3

Used Package Manager

npm

Validations

Metadata

Metadata

Assignees

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions