{"record":{"id":"3b18f2311fabf982","repo":"honojs/hono","slug":"server-requestip-is-not-a-function","errorCode":null,"errorMessage":"server.requestIP is not a function.","messagePattern":"server\\.requestIP is not a function\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"src/adapter/bun/conninfo.ts","lineNumber":23,"sourceCode":"/**\n * Get ConnInfo with Bun\n * @param c Context\n * @returns ConnInfo\n */\nexport const getConnInfo: GetConnInfo = (c: Context) => {\n  const server = getBunServer<{\n    requestIP?: (req: Request) => {\n      address: string\n      family: string\n      port: number\n    } | null\n  }>(c)\n\n  if (!server) {\n    throw new TypeError('env has to include the 2nd argument of fetch.')\n  }\n  if (typeof server.requestIP !== 'function') {\n    throw new TypeError('server.requestIP is not a function.')\n  }\n\n  // https://bun.sh/docs/runtime/http/server#server-requestip-request\n  // Returns null for closed requests or Unix domain sockets.\n  const info = server.requestIP(c.req.raw)\n\n  if (!info) {\n    return {\n      remote: {},\n    }\n  }\n\n  return {\n    remote: {\n      address: info.address,\n      addressType: info.family === 'IPv6' || info.family === 'IPv4' ? info.family : undefined,\n      port: info.port,\n    },","sourceCodeStart":5,"sourceCodeEnd":41,"githubUrl":"https://github.com/honojs/hono/blob/e2740d5a1bd0b4254e517e3af8b60789284bc7bd/src/adapter/bun/conninfo.ts#L5-L41","documentation":"getConnInfo() in the Bun adapter retrieves the client's address via Bun's server.requestIP(request) API. This error means the object found in `c.env.server` exists but does not expose a `requestIP` function — typically because the app was mounted through a non-Bun server (e.g. @hono/node-server also populates env with a server-like object) or the Bun version/runtime is one where requestIP is unavailable.","triggerScenarios":"Calling `getConnInfo(c)` from 'hono/bun' where `c.env.server` is present (Bun.serve was used or another adapter injected a server object) but that object lacks a `requestIP` method — e.g. running the Bun adapter code under Node with @hono/node-server, or an outdated/mismatched Bun runtime.","commonSituations":"Mixing adapters: importing getConnInfo from 'hono/bun' while serving with @hono/node-server; CI running tests under Node while the code assumes Bun; very old Bun versions before requestIP was added; custom objects placed in c.env that shadow the expected server shape.","solutions":["Import getConnInfo from the adapter matching your runtime: 'hono/bun' for Bun.serve, '@hono/node-server/conninfo' for Node","Upgrade Bun to a version supporting server.requestIP (bun upgrade)","Verify you actually start the app with Bun.serve({ fetch: app.fetch }) and not another server","Feature-detect before calling: `if (typeof server?.requestIP === 'function')` or wrap in try/catch and fall back to x-forwarded-for"],"exampleFix":"// before\nimport { getConnInfo } from 'hono/bun' // but served via @hono/node-server\nconst info = getConnInfo(c)\n\n// after (Node)\nimport { serve } from '@hono/node-server'\nimport { getConnInfo } from '@hono/node-server/conninfo'\nserve({ fetch: app.fetch })\nconst info = getConnInfo(c)","handlingStrategy":"type-guard","validationCode":"const canGetConnInfo = (c: Context) =>\n  typeof (c.env as any)?.server?.requestIP === 'function'\n\napp.get('/ip', (c) => canGetConnInfo(c) ? c.json(getConnInfo(c)) : c.text('n/a'))","typeGuard":"const supportsRequestIP = (env: unknown): env is { server: { requestIP(r: Request): unknown } } =>\n  typeof (env as any)?.server?.requestIP === 'function'","tryCatchPattern":"try { info = getConnInfo(c) } catch { info = parseXFF(c.req.header('x-forwarded-for')) }","preventionTips":["Import conninfo helpers from the adapter matching your runtime","Upgrade Bun regularly; requestIP is a Bun-specific API","Run tests under the same runtime the adapter targets"],"tags":["bun","adapter","conninfo","requestip","runtime-mismatch"],"backgroundTag":"wrong-runtime-adapter","analyzedSha":"e2740d5a1bd0b4254e517e3af8b60789284bc7bd","analyzedAt":"2026-08-28T10:18:08.750Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}