fcrozatier
fcrozatier

Reputation: 721

SvelteKit Node streams are no longer supported

Since node-fetch was replaced by undici in #5117 some of us encountered the error

Node streams are no longer supported — use a ReadableStream instead

like in this post

It is not easy to reproduce, for me the error occured only in production.

This is a self-answered question in case you have the same problem.

Upvotes: 0

Views: 711

Answers (1)

fcrozatier
fcrozatier

Reputation: 721

The error comes from src/runtime/server/utils.js L46 and is thrown after checking the _readableState property and some type on the response body of the request.

For me the problem was that my endpoint.ts was returning the fetch directly.

export async function post({request}){
  return fetch('...')
}

This used to work but not anymore since the fetch response is a complex object with the _readableState property. To fix this you have to consume the response and return a simpler object like

export async function post({request}){
  try {
    const res = await fetch('...')
    const data = await res.json()
    return {
      status: 200,
      body: JSON.stringify({...data}),
    }
  catch(error){
    return { status: 500}
  }
}

Upvotes: 1

Related Questions