TypeError: Circular reference detected #92

Closed
opened 2026-02-15 17:15:38 -05:00 by yindo · 9 comments
Owner

Originally created by @AndreaDelliGatti on GitHub (Sep 23, 2024).

I have the following error when run langgraph in a nextjs app

unhandledRejection: TypeError: Circular reference detected
    at _serialize (webpack-internal:///(action-browser)/../../node_modules/@langchain/langgraph-checkpoint/dist/serde/jsonplus.js:32:19)
    at eval (webpack-internal:///(action-browser)/../../node_modules/@langchain/langgraph-checkpoint/dist/serde/jsonplus.js:37:32)
    at Array.map (<anonymous>)
    at _serialize (webpack-internal:///(action-browser)/../../node_modules/@langchain/langgraph-checkpoint/dist/serde/jsonplus.js:37:18)
    at eval (webpack-internal:///(action-browser)/../../node_modules/@langchain/langgraph-checkpoint/dist/serde/jsonplus.js:46:98)
    at Array.map (<anonymous>)
    at _serialize (webpack-internal:///(action-browser)/../../node_modules/@langchain/langgraph-checkpoint/dist/serde/jsonplus.js:46:58)
    at eval (webpack-internal:///(action-browser)/../../node_modules/@langchain/langgraph-checkpoint/dist/serde/jsonplus.js:46:98)
    at Array.map (<anonymous>)
    at _serialize (webpack-internal:///(action-browser)/../../node_modules/@langchain/langgraph-checkpoint/dist/serde/jsonplus.js:46:58)
    at JsonPlusSerializer._dumps (webpack-internal:///(action-browser)/../../node_modules/@langchain/langgraph-checkpoint/dist/serde/jsonplus.js:153:31)
    at JsonPlusSerializer.dumpsTyped (webpack-internal:///(action-browser)/../../node_modules/@langchain/langgraph-checkpoint/dist/serde/jsonplus.js:160:34)
    at MemorySaver.put (webpack-internal:///(action-browser)/../../node_modules/@langchain/langgraph-checkpoint/dist/memory.js:210:53)
    at eval (webpack-internal:///(action-browser)/../../node_modules/@langchain/langgraph/dist/pregel/loop.js:260:39)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
Originally created by @AndreaDelliGatti on GitHub (Sep 23, 2024). I have the following error when run langgraph in a nextjs app ``` unhandledRejection: TypeError: Circular reference detected at _serialize (webpack-internal:///(action-browser)/../../node_modules/@langchain/langgraph-checkpoint/dist/serde/jsonplus.js:32:19) at eval (webpack-internal:///(action-browser)/../../node_modules/@langchain/langgraph-checkpoint/dist/serde/jsonplus.js:37:32) at Array.map (<anonymous>) at _serialize (webpack-internal:///(action-browser)/../../node_modules/@langchain/langgraph-checkpoint/dist/serde/jsonplus.js:37:18) at eval (webpack-internal:///(action-browser)/../../node_modules/@langchain/langgraph-checkpoint/dist/serde/jsonplus.js:46:98) at Array.map (<anonymous>) at _serialize (webpack-internal:///(action-browser)/../../node_modules/@langchain/langgraph-checkpoint/dist/serde/jsonplus.js:46:58) at eval (webpack-internal:///(action-browser)/../../node_modules/@langchain/langgraph-checkpoint/dist/serde/jsonplus.js:46:98) at Array.map (<anonymous>) at _serialize (webpack-internal:///(action-browser)/../../node_modules/@langchain/langgraph-checkpoint/dist/serde/jsonplus.js:46:58) at JsonPlusSerializer._dumps (webpack-internal:///(action-browser)/../../node_modules/@langchain/langgraph-checkpoint/dist/serde/jsonplus.js:153:31) at JsonPlusSerializer.dumpsTyped (webpack-internal:///(action-browser)/../../node_modules/@langchain/langgraph-checkpoint/dist/serde/jsonplus.js:160:34) at MemorySaver.put (webpack-internal:///(action-browser)/../../node_modules/@langchain/langgraph-checkpoint/dist/memory.js:210:53) at eval (webpack-internal:///(action-browser)/../../node_modules/@langchain/langgraph/dist/pregel/loop.js:260:39) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) ```
yindo closed this issue 2026-02-15 17:15:38 -05:00
Author
Owner

@AndreaDelliGatti commented on GitHub (Sep 23, 2024):

if i run the same graph inside a node process i have no problem. only when i run it server side in a nextjs web application.

@langchain/langgraph 0.2.8
@langchain/core 0.3.3
@langchain/community 0.3.2

@AndreaDelliGatti commented on GitHub (Sep 23, 2024): if i run the same graph inside a node process i have no problem. only when i run it server side in a nextjs web application. @langchain/langgraph 0.2.8 @langchain/core 0.3.3 @langchain/community 0.3.2
Author
Owner

@jacoblee93 commented on GitHub (Sep 23, 2024):

Hey @AndreaDelliGatti, will have a look at this today, I think I know what's causing it.

@jacoblee93 commented on GitHub (Sep 23, 2024): Hey @AndreaDelliGatti, will have a look at this today, I think I know what's causing it.
Author
Owner

@jacoblee93 commented on GitHub (Sep 23, 2024):

Actually - just so I'm sure - can you give me an example of your state and what you're storing in it?

@jacoblee93 commented on GitHub (Sep 23, 2024): Actually - just so I'm sure - can you give me an example of your state and what you're storing in it?
Author
Owner

@AndreaDelliGatti commented on GitHub (Sep 23, 2024):

@jacoblee93
Here an example:

const state = Annotation.Root({
    input: Annotation<BaseMessage>({
        reducer: (x: BaseMessage, y: BaseMessage) => y
    }),
    next: Annotation<string>({
        reducer: (x: string, y: string) => y
    }),
    sender: Annotation<string>({
        reducer: (x: string, y: string) => y
    }),
    messages: Annotation({
        reducer: (x: BaseMessage[], y: BaseMessage[]) => x.concat(y),
        default: () => [],
    }),
    data: Annotation({
        reducer: (a: Record<string,any>, b: Record<string,any>) => {
            return {
                ...a,
                ...b
            }
        },
        default: () => { return {} }
    })
})
@AndreaDelliGatti commented on GitHub (Sep 23, 2024): @jacoblee93 Here an example: ```typescript const state = Annotation.Root({ input: Annotation<BaseMessage>({ reducer: (x: BaseMessage, y: BaseMessage) => y }), next: Annotation<string>({ reducer: (x: string, y: string) => y }), sender: Annotation<string>({ reducer: (x: string, y: string) => y }), messages: Annotation({ reducer: (x: BaseMessage[], y: BaseMessage[]) => x.concat(y), default: () => [], }), data: Annotation({ reducer: (a: Record<string,any>, b: Record<string,any>) => { return { ...a, ...b } }, default: () => { return {} } }) }) ```
Author
Owner

@AndreaDelliGatti commented on GitHub (Sep 23, 2024):

@jacoblee93 the data property should contains BaseMessage and/or DocumentInterface

@AndreaDelliGatti commented on GitHub (Sep 23, 2024): @jacoblee93 the data property should contains BaseMessage and/or DocumentInterface
Author
Owner

@jacoblee93 commented on GitHub (Sep 23, 2024):

Got it - will have a look by the end of the day.

@jacoblee93 commented on GitHub (Sep 23, 2024): Got it - will have a look by the end of the day.
Author
Owner

@jacoblee93 commented on GitHub (Sep 23, 2024):

Hey @AndreaDelliGatti, I've pushed what I believe will be a fix - can you regenerate your lockfile or update the internal @langchain/langgraph-checkpoint package to 0.0.7?

@jacoblee93 commented on GitHub (Sep 23, 2024): Hey @AndreaDelliGatti, I've pushed what I believe will be a fix - can you regenerate your lockfile or update the internal `@langchain/langgraph-checkpoint` package to 0.0.7?
Author
Owner

@AndreaDelliGatti commented on GitHub (Sep 24, 2024):

Hi @jacoblee93 I deleted my lockfile and now everything seems ok. thx.

@AndreaDelliGatti commented on GitHub (Sep 24, 2024): Hi @jacoblee93 I deleted my lockfile and now everything seems ok. thx.
Author
Owner

@jacoblee93 commented on GitHub (Sep 24, 2024):

Awesome! Thanks again for the report.

@jacoblee93 commented on GitHub (Sep 24, 2024): Awesome! Thanks again for the report.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langgraphjs#92