Running in Firebase Function #85

Open
opened 2026-02-15 17:15:35 -05:00 by yindo · 5 comments
Owner

Originally created by @objectiveSee on GitHub (Sep 10, 2024).

I am getting run-time error when trying to run LangGraph inside a Firebase function.

Firebase Function:

exports.langgraph = onRequest(async (request, response) => {
  const articleId = request.query.articleId as string;
  const workflow = getWorkflow();

  const result = await workflow.invoke({
    articleId,
  });
  response.json(result);
});

Workflow:

import { END, START, StateGraph } from "@langchain/langgraph";
import { AgentState } from "./state";
import { testNode, wikipediaNode } from "./nodes";
import { researcherNode } from "./nodes/researcher";

export const getWorkflow = () => {
  const workflow = new StateGraph(AgentState)
    .addNode("final", testNode)
    .addNode("wikipedia", wikipediaNode)
    .addNode("researcher", researcherNode)
    .addEdge(START, "wikipedia")
    .addEdge("wikipedia", "researcher")
    .addEdge("researcher", "final")
    .addEdge("final", END);

  return workflow.compile();
};

Error:

⚠  functions: Error: Expected a Runnable, function or object.
Instead got an unsupported type.
    at _coerceToRunnable (/Users/user/workspace/foo-api/functions/node_modules/@langchain/core/dist/runnables/base.cjs:1857:15)
    at StateGraph.addNode (/Users/user/workspace/foo-api/functions/node_modules/@langchain/langgraph/dist/graph/state.cjs:204:57)
    at getWorkflow (/Users/user/workspace/foo-api/functions/lib/src/graph/index.js:11:10)
    at /Users/user/workspace/foo-api/functions/lib/src/index.js:225:46
    at /Users/user/workspace/foo-api/functions/node_modules/firebase-functions/lib/v2/providers/https.js:65:29
    at cors (/Users/user/workspace/foo-api/functions/node_modules/cors/lib/index.js:188:7)
    at /Users/user/workspace/foo-api/functions/node_modules/cors/lib/index.js:224:17
    at originCallback (/Users/user/workspace/foo-api/functions/node_modules/cors/lib/index.js:214:15)
    at /Users/user/workspace/foo-api/functions/node_modules/cors/lib/index.js:219:13
    at optionsCallback (/Users/user/workspace/foo-api/functions/node_modules/cors/lib/index.js:199:9)
⚠  Your function was killed because it raised an unhandled error.

Any thoughts on why this might happen? My code worked with LangGraph studio. I've tried two ways of doing this: 1) the workflow is compiled at script start time, and 2) on demand via getWorkflow(). Both fail with same error.

Thanks

Packages:

    "@langchain/anthropic": "^0.2.17",
    "@langchain/core": "^0.2.31",
    "@langchain/langgraph": "^0.2.2",
    "@langchain/openai": "^0.2.10",
Originally created by @objectiveSee on GitHub (Sep 10, 2024). I am getting run-time error when trying to run LangGraph inside a Firebase function. Firebase Function: ``` exports.langgraph = onRequest(async (request, response) => { const articleId = request.query.articleId as string; const workflow = getWorkflow(); const result = await workflow.invoke({ articleId, }); response.json(result); }); ``` Workflow: ``` import { END, START, StateGraph } from "@langchain/langgraph"; import { AgentState } from "./state"; import { testNode, wikipediaNode } from "./nodes"; import { researcherNode } from "./nodes/researcher"; export const getWorkflow = () => { const workflow = new StateGraph(AgentState) .addNode("final", testNode) .addNode("wikipedia", wikipediaNode) .addNode("researcher", researcherNode) .addEdge(START, "wikipedia") .addEdge("wikipedia", "researcher") .addEdge("researcher", "final") .addEdge("final", END); return workflow.compile(); }; ``` Error: ``` ⚠ functions: Error: Expected a Runnable, function or object. Instead got an unsupported type. at _coerceToRunnable (/Users/user/workspace/foo-api/functions/node_modules/@langchain/core/dist/runnables/base.cjs:1857:15) at StateGraph.addNode (/Users/user/workspace/foo-api/functions/node_modules/@langchain/langgraph/dist/graph/state.cjs:204:57) at getWorkflow (/Users/user/workspace/foo-api/functions/lib/src/graph/index.js:11:10) at /Users/user/workspace/foo-api/functions/lib/src/index.js:225:46 at /Users/user/workspace/foo-api/functions/node_modules/firebase-functions/lib/v2/providers/https.js:65:29 at cors (/Users/user/workspace/foo-api/functions/node_modules/cors/lib/index.js:188:7) at /Users/user/workspace/foo-api/functions/node_modules/cors/lib/index.js:224:17 at originCallback (/Users/user/workspace/foo-api/functions/node_modules/cors/lib/index.js:214:15) at /Users/user/workspace/foo-api/functions/node_modules/cors/lib/index.js:219:13 at optionsCallback (/Users/user/workspace/foo-api/functions/node_modules/cors/lib/index.js:199:9) ⚠ Your function was killed because it raised an unhandled error. ``` Any thoughts on why this might happen? My code worked with LangGraph studio. I've tried two ways of doing this: 1) the workflow is compiled at script start time, and 2) on demand via getWorkflow(). Both fail with same error. Thanks Packages: ``` "@langchain/anthropic": "^0.2.17", "@langchain/core": "^0.2.31", "@langchain/langgraph": "^0.2.2", "@langchain/openai": "^0.2.10", ```
yindo added the enhancement label 2026-02-15 17:15:35 -05:00
Author
Owner

@objectiveSee commented on GitHub (Sep 10, 2024):

Follow-up: Looks like the issue is what the way nodes are defined. This works fine in LangGraph Studio, but fails at run-time when I hook it up to a Firebase Function. It seems like the graph doesn't like the way the node is defined, which is odd because I am following the docs. Is there something I am missing?

Node:

export const wikipediaNode = async (state: typeof AgentState.State) => {
  const x = state.articleId;
  const articleContent = await fetchArticleContent(Number(x));
  return { article: articleContent };
};

Simplified Example:

FAILS

  workflow = new StateGraph(AgentState)
    .addNode("wiki", wikipediaNode)
    .addEdge(START, "wiki")
    .addEdge("wiki", END);

SUCEEDS

workflow = new StateGraph(AgentState).addEdge(START, END);
@objectiveSee commented on GitHub (Sep 10, 2024): Follow-up: Looks like the issue is what the way nodes are defined. This works fine in LangGraph Studio, but fails at run-time when I hook it up to a Firebase Function. It seems like the graph doesn't like the way the node is defined, which is odd because I am following the docs. Is there something I am missing? Node: ``` export const wikipediaNode = async (state: typeof AgentState.State) => { const x = state.articleId; const articleContent = await fetchArticleContent(Number(x)); return { article: articleContent }; }; ``` Simplified Example: ❌ FAILS ``` workflow = new StateGraph(AgentState) .addNode("wiki", wikipediaNode) .addEdge(START, "wiki") .addEdge("wiki", END); ``` ✅ SUCEEDS ``` workflow = new StateGraph(AgentState).addEdge(START, END); ```
Author
Owner

@jacoblee93 commented on GitHub (Oct 8, 2024):

Sorry for the delay - this is pretty odd. It should accept a function. Logging wikipediaNode just gives back a function?

Is there anything unique about Firebase Functions as a runtime?

@jacoblee93 commented on GitHub (Oct 8, 2024): Sorry for the delay - this is pretty odd. It should accept a function. Logging `wikipediaNode` just gives back a function? Is there anything unique about Firebase Functions as a runtime?
Author
Owner

@kdawgwilk commented on GitHub (Oct 8, 2024):

They are just using NodeJS runtime although you can control which NodeJS version. I wonder if its specific to a NodeJS version? @objectiveSee what version of NodeJS are you using in your firebase functions?

@kdawgwilk commented on GitHub (Oct 8, 2024): They are just using NodeJS runtime although you can control which NodeJS version. I wonder if its specific to a NodeJS version? @objectiveSee what version of NodeJS are you using in your firebase functions?
Author
Owner

@objectiveSee commented on GitHub (Oct 8, 2024):

This is running on node 22. What version have you been using? Have you gotten this to work?

@objectiveSee commented on GitHub (Oct 8, 2024): This is running on node 22. What version have you been using? Have you gotten this to work?
Author
Owner

@kdawgwilk commented on GitHub (Oct 9, 2024):

Try adding .js file extensions on your imports

@kdawgwilk commented on GitHub (Oct 9, 2024): Try adding `.js` file extensions on your imports
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langgraphjs#85