Skip to content

TypeError: Request constructor: Expected init.body ("URLSearchParams {}") to be an instance of URLSearchParams. #7906

@ghost

Description

Describe the bug

I wanted to open the bug report with jsdom but I failed to reproduce the error without vitest so here we go.

When you are using Node 22.15.0 and you are using "environment": "jsdom" in vitest.config.ts you cannot construct Request objects with URLSearchParams bodies or else TypeError will be thrown:

TypeError: Request constructor: Expected init.body ("URLSearchParams {}") to be an instance of URLSearchParams.

You can successfully construct Request objects again when you override globalThis.URLSearchParams with node:urls URLSearchParams.

Reproduction

The StackBlitz here just presents the setup. I cannot change the Node version in StackBlitz to 22.15.0. And because of this the bug will not show up.

System Info

System:
    OS: Linux 5.15 Debian GNU/Linux 11 (bullseye) 11 (bullseye)
    CPU: (12) x64 13th Gen Intel(R) Core(TM) i7-1365U
    Memory: 2.69 GB / 7.59 GB
    Container: Yes
    Shell: 5.1.4 - /bin/bash
  Binaries:
    Node: 23.8.0 - /run/user/1000/fnm_multishells/86411_1745923856293/bin/node
    npm: 10.9.2 - /run/user/1000/fnm_multishells/86411_1745923856293/bin/npm
    pnpm: 10.4.1 - /run/user/1000/fnm_multishells/86411_1745923856293/bin/pnpm
  npmPackages:
    vitest: ^3.1.2 => 3.1.2

Used Package Manager

pnpm

Validations

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions