Sveltekit节点流不再支持

发布于 2025-02-13 20:08:13 字数 479 浏览 0 评论 0原文

由于node-fetchundiCi#5117 我们中的一些人遇到了错误

不再支持节点流 - 使用readableStream

不容易复制,因为我的错误仅在生产中发生。

如果您有同样的问题,这是一个自我解决的问题。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你的背包 2025-02-20 20:08:13

The error comes from

对我来说,问题是我的endpoint.ts直接返回fetch

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

这曾经工作,但不再工作,因为fetch响应是一个复杂的对象,具有_ReadableState属性。要解决此问题,您必须消耗响应并返回一个更简单的对象

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}
  }
}

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}
  }
}

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文