Visitar URL original
Doesn't play nice with node v18 undici fetch · Issue #533 · form-data/form-data · GitHub
Skip to content

Doesn't play nice with node v18 undici fetch #533

Open

Description

@wmertens

In Node 18 the standards-compliant undici fetch is available, and it accepts Node's Readable Stream as a body as well as the standard Web Streams.

The problem is that new FormData() doesn't return an object that is recognized as a Readable.

Workaround:

import {PassThrough} from 'stream'
// ...
const pt = new PassThrough()
formData.pipe(pt)
fetch(url, {
  // ...
  body: pt
})

You can test the problem in Node 18 by running the following, which will throw:

import {Readable} from 'stream'
// ...
Readable.toWeb(formData)

Probably Readable needs to be in the prototype chain?

Activity

  1. jimmywarting commented on Apr 12, 2023

    @jimmywarting

    instead of using form-data use the FormData provided by nodejs/undici itself

  2. wmertens commented on Apr 12, 2023

    @wmertens
    Author

    @jimmywarting and forego all the nice features?

  3. jimmywarting commented on Apr 12, 2023

    @jimmywarting

    like what features?

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions