Closed
Description
What version of Hono are you using?
4.3.2
What runtime/platform is your app running on?
Node
What steps can reproduce the bug?
import {Hono} from 'hono'
import {bodyLimit} from 'hono/body-limit'
const app = new Hono()
app.use(bodyLimit({maxSize: 100 * 1024})) // 100kb
app.post('/hello', async (context) => {
return context.json({message: 'Hello, World!'})
})
const response = await app.request('/hello', {
method: 'POST',
body: JSON.stringify({foo: 'bar'}),
})
console.log('response:', response.status)
What is the expected behavior?
response: 200
What do you see instead?
TypeError: RequestInit: duplex option is required when sending a body.
at new Request (node:internal/deps/undici/undici:5082:19)
at bodyLimit2 (file:///.../node_modules/hono/dist/middleware/body-limit/index.js:48:17)
at dispatch (file:///.../node_modules/hono/dist/compose.js:29:23)
at file:///.../node_modules/hono/dist/compose.js:6:12
at file:///.../node_modules/hono/dist/hono-base.js:188:31
at Hono.dispatch (file:///.../node_modules/hono/dist/hono-base.js:198:7)
at Hono.fetch (file:///.../node_modules/hono/dist/hono-base.js:201:17)
at Hono.request (file:///.../node_modules/hono/dist/hono-base.js:213:17)
at <anonymous> (/.../sandbox.ts:12:28)
at ModuleJob.run (node:internal/modules/esm/module_job:235:25)
response: 500
Additional information
Same app set up is working without any error when started as a node server and fetch response, see example below
import {Hono} from 'hono'
import {bodyLimit} from 'hono/body-limit'
import {serve} from '@hono/node-server'
const app = new Hono()
app.use(bodyLimit({maxSize: 1024 * 1024})) // 1mb
app.post('/hello', async (context) => {
return context.json({message: 'Hello, World!'})
})
// const response = await app.request('/hello', {
// method: 'POST',
// body: JSON.stringify({foo: 'bar'}),
// })
// console.log('response:', response.status)
serve({
fetch: app.fetch,
port: 3000,
})
const response = await fetch('http://localhost:3000/hello', {
method: 'POST',
body: JSON.stringify({foo: 'bar'}),
})
console.log('response:', response.status)