Skip to content

hono logger() throws 'TypeError: test is not a function' at runtime inside the middleware path (follow-up to #1725) #1731

Description

@proggeramlug

Follow-up to #1725 (which fixed the compile error). hono/logger now compiles, but throws at runtime.

Repro (Perry @ main 65de8ec, hono@4.10)

import { Hono } from 'hono'
import { logger } from 'hono/logger'
const app = new Hono()
app.use('*', logger())
app.get('/', (c) => c.text('ok'))
const main = async () => {
  const res = await app.fetch(new Request('http://localhost/'))
  console.log('status', res.status, await res.text())
}
main().catch((e) => console.log('THREW', String(e?.message ?? e)))

Observed: THREW TypeError: test is not a function (deterministic). Via @hono/perry-server + serve(), every request returns HTTP 500.

What's odd / where it isn't

  • hono/utils/color's getColorEnabledAsync() — which the logger awaits in colorStatus — runs fine standalone (await getColorEnabledAsync()true), even with import { Hono } present.
  • It only fails when invoked inside the Hono middleware-execution path (logger()app.usecomposeawait next()colorStatusgetColorEnabledAsync).
  • A custom app.use('*', async (c, next) => { await next(); await getColorEnabledAsync() }) produces no output at all (the async/middleware chain silently breaks).
  • The color helper's source has no .test( — so test is not a function is coming from Perry's machinery (async-compose / dynamic-import-resolution for the import("cloudflare:workers") branch in getColorEnabledAsync), exposed only in this execution context.

So this is a context-sensitive codegen/async bug in the middleware path, not a missing API. It's the last gap on the #1655 acceptance program's app.use('*', logger()) line; the rest (HTML, JSON, query, POST) works end-to-end.

Related

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