You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Request/Response.formData() throws ERR_ASSERTION on a multipart file part when globalThis.File is replaced #67516
AssertionError [ERR_ASSERTION]: The expression evaluated to a falsy value:
assert(typeof value === "string" && webidl.is.USVString(value) || webidl.is.File(value))
at multipartFormDataParser (node:internal/deps/undici/undici:...)
How often does it reproduce?
Always.
What is the expected behavior?
formData() returns a FormData whose "f" entry is a file with the content hello, as on v22. It shouldn't depend on what the global File binding currently points to.
What do you see instead?
multipartFormDataParser creates the part with new File(...), which looks up the global File at call time. It then checks the result with webidl.is.File, which is MakeTypeAssertion(File) taken from Node's own File when the module loads. Once the global is replaced, the object it just created fails the check.
Additional information
This is what happens under DOM test environments: vitest and jest with jsdom install the DOM's File on globalThis. Any Request.formData() on a multipart body with a file part then fails, which includes every MSW request handler that reads an upload.
The vitest + jsdom project below reproduces it in that setting (npm i && npx vitest run): it passes on v22.23.3 and fails on v24.22.2 and v26.13.1.
import{expect,test}from"vitest";// Under jsdom, globalThis.File is jsdom's. Node's Request.formData() then fails on a file part.test("Request.formData() parses a multipart file part under jsdom",async()=>{constbody="--b\r\n"+'Content-Disposition: form-data; name="f"; filename="a.txt"\r\n'+"Content-Type: text/plain\r\n\r\n"+"hello\r\n"+"--b--\r\n";constreq=newRequest("http://example.invalid/",{method: "POST",headers: {"content-type": "multipart/form-data; boundary=b"},
body,});constpart=(awaitreq.formData()).get("f");expect(awaitpart.text()).toBe("hello");});
A possible fix: construct the part with the same internal File the brand check uses, instead of the global binding.
Activity