Skip to content

[Bug]: firebase functions Context is not finalized #312

@ShaMan123

Description

@ShaMan123

I am trying to use hono with firebase functions without success.
Getting Context is not finalized

Server

import { getRequestListener } from "@hono/node-server";
import { onRequest } from "firebase-functions/https";
import { Hono } from "hono";

app.post("/endpoint", (c) => c.json({ ok: true, endpoint: true }));

app.post("*", (c) => c.json({ ok: true }));

app.notFound((c) => {
  console.log("notFound", c.req.url);
  return c.json({ ok: false, url: c.req.url });
});

app.onError((error, c) => {
  console.log("onError", error);
  return c.json({ ok: false, url: c.req.url, error: error.message });
});

export const api = onRequest(getRequestListener(app.fetch));

Client

      const endPoint = "/api/endpoint";
      const res = await fetch(endPoint, {
        method: "POST",
        headers: {
          "content-type": "application/json",
        },
      });
      console.log(await res.json());

firebase.json

{
  "hosting": {
    "public": "dist",
    "ignore": ["firebase.json", "**/.*", "**/node_modules/**"],
    "predeploy": ["npm test", "npm run build"],
    "rewrites": [
      {
        "source": "/api{,/**}",
        "function": "api"
      },
      {
        "source": "**",
        "destination": "/index.html"
      }
    ]
  },
  "functions": [
    {
      "source": "functions",
      "codebase": "default",
      "disallowLegacyRuntimeConfig": true,
      "ignore": [
        "node_modules",
        ".git",
        "firebase-debug.log",
        "firebase-debug.*.log",
        "*.local"
      ],
      "predeploy": [
        "npm --prefix \"$RESOURCE_DIR\" run lint",
        "npm --prefix \"$RESOURCE_DIR\" run build"
      ]
    }
  ],
  "emulators": {
    "auth": {
      "port": 9099
    },
    "functions": {
      "port": 5001,
      "region": "us-central1"
    },
    "firestore": {
      "port": 8080
    },
    "hosting": {
      "port": 5002
    },
    "ui": {
      "enabled": true
    },
    "singleProjectMode": true
  }
}

Error

>  onError Error: Context is not finalized. Did you forget to return a Response object or `await next()`?
>      at /Users/shaman123/DEV/rakto/functions/node_modules/hono/dist/cjs/hono-base.js:325:17
>      at process.processTicksAndRejections (node:internal/process/task_queues:103:5)
>      at async responseViaResponseObject (/Users/shaman123/DEV/rakto/functions/node_modules/@hono/node-server/dist/index.js:441:13)
>      at async /Users/shaman123/DEV/rakto/functions/node_modules/@hono/node-server/dist/index.js:580:14
>      at async /Users/shaman123/DEV/rakto/functions/node_modules/firebase-functions/lib/common/providers/https.js:566:4
>      at async runFunction (/Users/shaman123/.nvm/versions/node/v24.12.0/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:399:9)
>      at async runHTTPS (/Users/shaman123/.nvm/versions/node/v24.12.0/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:424:5)
>      at async /Users/shaman123/.nvm/versions/node/v24.12.0/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:585:21

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