Skip to content
This repository was archived by the owner on Jan 23, 2026. It is now read-only.
This repository was archived by the owner on Jan 23, 2026. It is now read-only.

Upload stream fetch request fails in SvelteKit #146

Description

@rexmondo

Bug report

Not sure if this is the ideal place to file this bug, but I decided on here because my client implementation is the one recommended here.

Describe the bug

When trying to upload a ReadableStream to a bucket using SvelteKit 1.0.0-next.526 and the storage-js client like so:

const { data, error } = await supabase.storage.from('processed').upload('file.jpg', someReadableStream)

I got this error:

TypeError: RequestInit: duplex option is required when sending a body.
    at fetch (/Users/ben/projects/svelte-surfshots/node_modules/.pnpm/undici@5.14.0/node_modules/undici/index.js:105:13)

To Reproduce

  1. Follow supabase install instructions for a new SvelteKit project here
  2. Set up auth as per auth-helpers
  3. Set up a public bucket and add upload permission policy for any authenticated user
  4. Try to upload either a node:stream Readable or a node:stream/web ReadableStream from a +server.ts file on a route of your choosing (I tried both and they threw the same error)

Expected behavior

The file should be added to the bucket

System information

  • OS: macOS 12.6
  • Browser (if applies): Chrome 109.0.5414.119
  • Version of supabase-js: 2.2.3
  • Version of Node.js: 18.13.0 (lts)

Additional context

  • Recently the whatwg spec has been shifted to require a {duplex: 'half' } or { duplex: 'full' } option to be passed to the RequestInit when performing a fetch with a ReadableStream. See here.
  • Undici started following the spec and throwing a TypeError when the option isn't present during a streaming fetch call in v5.12.0. See here
  • SvelteKit pinned Undici at v5.12.0 in a recent release (now they are up to v5.14.0)
  • After digging around in storage-js and tracking the (rather labyrinthine) load sequence from auth-helper down to the fetch call the upload eventually flushes to, I determined that implementation was indeed calling undici and had no extra mechanism to pass in more options to the RequestInit. The lines below fix the request init to only contain method, body and header
     const res = await this.fetch(`${this.url}/object/${_path}`, {
         method,
         body: body as BodyInit,
         headers,
       })
  • I've confirmed that the error goes away by hotpatching the fetch function in the client instantiation as follows:
    export const supabaseClient = createClient(PUBLIC_SUPABASE_URL, PUBLIC_SUPABASE_ANON_KEY, {
      global: {
        // TODONT!!!!
        async fetch(path, opts) {
          return global.fetch(path, { ...opts, duplex: 'half' })
        }
      }
    })
    But I suspect this will break other things.

Activity

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

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions