sindresorhus / ky

🌳 Tiny & elegant JavaScript HTTP client based on the Fetch API
MIT License
13.62k stars 363 forks source link

Error: `unsupported BodyInit type` on some runtimes #530

Closed Airkro closed 9 months ago

Airkro commented 1 year ago

After import 'ky' (> 0.31.1), the Error: unsupported BodyInit type will block all code runs.

Since: v0.31.2

export const supportsStreams = (() => {
    let duplexAccessed = false;
    let hasContentType = false;
    const supportsReadableStream = typeof globalThis.ReadableStream === 'function';

    if (supportsReadableStream) {
        hasContentType = new globalThis.Request('', {
            body: new globalThis.ReadableStream(),                   //  <--- this error trigger error
            method: 'POST',
            get duplex() {
                duplexAccessed = true;
                return 'half';
            },
        }).headers.has('Content-Type');
    }

    return duplexAccessed && !hasContentType;
})();

Can we skip this step?

sindresorhus commented 1 year ago

What runtimes?