honojs / node-server

Node.js Server for Hono

Home Page:https://hono.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`serve(app)` crashes with `TypeError: headers is not iterable`

sparrowsl opened this issue · comments

~/Desktop/hono-test/node_modules/@hono/node-server/dist/index.mjs:178                                                                                
for (const [k, v] of headers) {                                                                                                                                       
TypeError: headers is not iterable                                       
  at buildOutgoingHttpHeaders (~/Desktop/hono-test/node_modules/@hono/node-server/dist/index.mjs:178:
  at responseViaResponseObject (~/Desktop/hono-test/node_modules/@hono/node-server/dist/index.mjs:345:27)                                      
  at process.processTicksAndRejections (node:internal/process/task_queues:95:5)                                                                                       
Node.js v20.14.0   

I get this error above when I try to access the endpoint.

import { serve } from '@hono/node-server'
import { Hono } from 'hono'
import { logger } from "hono/logger"

const app = new Hono()
app.use(logger)

app.get('/', (c) => {
  return c.text('Hello Hono!')
})

const port = 3000
console.log(`Server is running on port ${port}`)

serve({
  fetch: app.fetch,
  port
})

the serve(app) doesnt work on this and current version is hono: 4.4.6 and @hono/node-server: 1.11.3
This is the base repro
repro

Hi @sparrowsl thank you for the issue.

You should write the following for the Logger Middleware:

const app = new Hono()
app.use(logger()) // <---

With this answer, your problem will be resolved, but the error message will not be friendly.

@usualoma Any thoughts?

If it runs on such the Bun, it will throw the error like the following, which we can know we don't return Response correctly:

CleanShot 2024-06-14 at 23 41 41@2x

@yusukebe
We'll update '@hono/node-server' so that we can throw nifty exceptions!