sindresorhus / ky

🌳 Tiny & elegant JavaScript HTTP client based on the Fetch API

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

"fetch() request with GET/HEAD/OPTIONS method cannot have body" in Bun

dimonnwc3 opened this issue · comments

Following code throws an error:

const res = await ky.post(baseURL("/api/v1/countries"), {
      json: { email: "aaaaaaa", name: "a" },
})
TypeError: fetch() request with GET/HEAD/OPTIONS method cannot have body.
code: "ERR_INVALID_ARG_VALUE"
❯ bun --version
1.0.2
"ky": "^1.0.1",

I recommend opening an issue on Bun. We have a test to prove it works fine in Node.js:

ky/test/fetch.ts

Lines 62 to 66 in 98d76e6

test('options are correctly passed to Fetch #2', async t => {
const fixture = {x: true};
const json = await ky.post('https://httpbin.org/anything', {json: fixture}).json();
t.deepEqual(json.json, fixture);
});

resolved with this: oven-sh/bun#6144