Skip to content

FormData request body crashes with "Cannot read properties of undefined (reading '_buffer')" on jsdom 30.1.0 #841

Closed

Description

@Greidal

Describe the bug

Sending a FormData body (via axios, using the XHR interceptor under jsdom) throws
a TypeError when a Blob/File entry is present in the form, since upgrading
jsdom from 30.0.1 to 30.1.0. jsdom 30.0.1 works fine with the same test.

Stack trace

TypeError: Cannot read properties of undefined (reading '_buffer')
at invokeTheCallbackFunction (node_modules/jsdom/lib/generated/idl/Function.js:19:26)
at FormData.forEach (node_modules/jsdom/lib/generated/idl/FormData.js:420:18)
at Object.construct (node_modules/@mswjs/interceptors/src/interceptors/ClientRequest/utils/recordRawHeaders.ts:207:32)
at new FetchRequest (node_modules/@mswjs/interceptors/src/utils/fetchUtils.ts:73:4)
at XMLHttpRequestController.toFetchApiRequest (node_modules/@mswjs/interceptors/src/interceptors/XMLHttpRequest/XMLHttpRequestController.ts:675:25)
at XMLHttpRequest.methodCall (node_modules/@mswjs/interceptors/src/interceptors/XMLHttpRequest/XMLHttpRequestController.ts:170:38)
at Axios.request (node_modules/axios/lib/core/Axios.js:48:43)

To Reproduce

import { setupServer } from "msw/node";
import { http, HttpResponse } from "msw";
import axios from "axios";

const server = setupServer(
  http.post("*/upload", ({ request }) =>
    HttpResponse.json({ contentType: request.headers.get("content-type") })
  )
);
server.listen();

const form = new FormData();
form.append("file", new Blob(["hello"], { type: "text/plain" }), "hello.txt");

await axios.post("/upload", form); // throws

Run under vitest (or Jest) with environment: "jsdom".

Expected behavior

The request goes through and the mocked response is returned, as it does on jsdom 30.0.1.

Environment

  • @mswjs/interceptors (via msw): 2.15.0
  • jsdom: 30.1.0 (30.0.1 is fine)
  • vitest: 4.1.11
  • Node: 24.19.0

Additional context

This looks like the same root cause as
vitest-dev/vitest#11294 (jsdom renaming a private
field vitest's makeCompatBlob reads from Blob/File) — recordRawHeaders.ts
here reads a jsdom-internal _buffer field directly while iterating a
FormData's entries, and that field appears to no longer be present as of
jsdom 30.1.0.

Activity

  1. kettanaito commented on Sep 21, 2026

    @kettanaito
    Member

    Hi @Greidal. Thanks for reporting. This doesn't seem like an issue with Interceptors. We aren't reading any internal properties on FormData or any other global APIs. Please raise this with JSDOM and kindly ask them to fix the bug.

  2. Greidal commented on Sep 21, 2026

    @Greidal
    Author

    Thanks for the quick look, and sorry for the bad lead - you're right, I had misread the stack trace as Interceptors reading an internal property. Confirmed it isn't: I reproduced the crash with no Interceptors/msw/axios involved at all, just

    const form = new FormData()
    form.append('file', new Blob(['hello'], { type: 'text/plain' }), 'hello.txt')
    new Request('http://x.test/upload', { method: 'POST', body: form })

    under vitest's jsdom environment (vitest@4.1.11, jsdom@30.1.0, Node 24.19.0) - same Cannot read properties of undefined (reading '_buffer') at invokeTheCallbackFunction/FormData.forEach inside jsdom itself. Filing against jsdom with this repro. Thanks again, and apologies for the noise here.

  3. Greidal commented on Sep 21, 2026

    @Greidal
    Author
  4. Greidal commented on Sep 21, 2026

    @Greidal
    Author

    Correction to my last comment: it wasn't jsdom either. Traced it further to vitest's own jsdom-environment compat shim (makeCompatBlob/makeCompatFormData in packages/vitest/src/integrations/env/jsdom.ts) - it locates jsdom's internal Blob storage via a brittle Object.getOwnPropertySymbols(...)[0] heuristic that no longer resolves on jsdom 30.1.0. Closed the jsdom issue, filed the real findings at vitest-dev/vitest#11294 (reopening a previously-closed-but-insufficiently-fixed issue there). Sorry again for the back-and-forth.

  5. kettanaito commented on Sep 22, 2026

    @kettanaito
    Member

    Ha! Interesting find. Thanks for looking into it, @Greidal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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