Skip to content

Using Zod 4 results in cryptic TypeError during runtime #938

@mjakl

Description

@mjakl

Stagehand (I'm using version 2.4.2) is not working with Zod 4, running the example from the quickstart with Zod 4 results in this error:

Full error:
schema._def.shape is not a function
    at StagehandAPI.<anonymous> (.../node_modules/@browserbasehq/stagehand/dist/index.js:4550:23)
    at Generator.next (<anonymous>)
    at fulfilled (.../node_modules/@browserbasehq/stagehand/dist/index.js:66:24)
    at process.processTicksAndRejections (node:internal/process/task_queues:105:5)

Workaround: Falling back to Zod ^3 resolves the problem.


More detailed error output:

 StagehandResponseParseError  Failed to parse server response, StagehandResponseParseError
error stack:
  • index.js	StagehandAPI.<anonymous>
	/node_modules/@browserbasehq/stagehand/dist/index.js:4560
  •

  • index.js	fulfilled
	/node_modules/@browserbasehq/stagehand/dist/index.js:66
  • task_queues	process.processTicksAndRejections
	internal/process/task_queues:105
[2025-08-03 17:32:36.228 +0200] INFO: running extract
    category: "extract"
    instruction: "extract the main heading of the page"
    requestId: "5krxa0u1zc"
    modelName: "claude-sonnet-4-20250514"
[2025-08-03 17:32:36.228 +0200] INFO: starting extraction using a11y tree
    category: "extraction"
    instruction: "extract the main heading of the page"
[2025-08-03 17:32:36.906 +0200] INFO: got accessibility tree in 8 ms
    category: "observation"
[2025-08-03 17:32:36.906 +0200] INFO: Got accessibility tree data
    category: "extraction"
[2025-08-03 17:32:36.906 +0200] INFO: error extracting
    category: "extract"
    trace: "TypeError: schema._def.shape is not a function\n    at transformUrlStringsToNumericIds (/app/node_modules/.pnpm/@browserbasehq+stagehand@2.4.2-alpha-c20adb95539fed8c56a4aa413262a9c65a8e6474_deepmerge_c9e3182dcbea2ff6d4ea36ddebc2e021/node_modules/@browserbasehq/stagehand/dist/index.js:3240:29)\n    at StagehandExtractHandler.<anonymous> (/app/node_modules/.pnpm/@browserbasehq+stagehand@2.4.2-alpha-c20adb95539fed8c56a4aa413262a9c65a8e6474_deepmerge_c9e3182dcbea2ff6d4ea36ddebc2e021/node_modules/@browserbasehq/stagehand/dist/index.js:3167:50)\n    at Generator.next (<anonymous>)\n    at fulfilled (/app/node_modules/.pnpm/@browserbasehq+stagehand@2.4.2-alpha-c20adb95539fed8c56a4aa413262a9c65a8e6474_deepmerge_c9e3182dcbea2ff6d4ea36ddebc2e021/node_modules/@browserbasehq/stagehand/dist/index.js:66:24)"
    error: "schema._def.shape is not a function"

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