vercel/next.js · error · SerializableError

Error serializing `${path}` returned from `${method}` in "${

Error message

Error serializing `${path}` returned from `${method}` in "${page}".
Reason: invariant: Unknown error encountered in Array.

What it means

Thrown by isSerializableProps() as a defensive invariant when an Array passes Array.isArray and begins traversal, but the recursive every() check returns false without any inner check throwing. Like [116] for the Object branch, this is the 'unreachable' guard for arrays; reaching it implies the per-element isSerializable returned false unexpectedly rather than throwing a precise SerializableError.

Source

Thrown at packages/next/src/lib/is-serializable-props.ts:118

        method,
        path,
        `invariant: Unknown error encountered in Object.`
      )
    }

    if (Array.isArray(value)) {
      visit(refs, value, path)

      if (
        value.every((nestedValue, index) => {
          const newRefs = new Map(refs)
          return isSerializable(newRefs, nestedValue, `${path}[${index}]`)
        })
      ) {
        return true
      }

      throw new SerializableError(
        page,
        method,
        path,
        `invariant: Unknown error encountered in Array.`
      )
    }

    // None of these can be expressed as JSON:
    // const type: "bigint" | "symbol" | "object" | "function"
    throw new SerializableError(
      page,
      method,
      path,
      '`' +
        type +
        '`' +
        (type === 'object'
          ? ` ("${Object.prototype.toString.call(value)}")`

View on GitHub (pinned to 0ae8c72462)

Solutions

  1. Normalize the array: `[...arr]` and map elements through JSON.parse(JSON.stringify(x)) before returning.
  2. Replace Proxy/exotic elements with plain values.
  3. If reproducible with normal data, report a Next.js bug — this branch should be unreachable.
  4. Update to the latest Next.js patch.

Example fix

// before
return { props: { items: new Proxy([], {}) } }
// after
return { props: { items: [...plainItems] } }
Defensive patterns

Strategy: validation

Validate before calling

function normalizeArray(arr: unknown[]): unknown[] {
  return JSON.parse(JSON.stringify(arr))
}
// return { props: { items: normalizeArray(rawItems) } }

Type guard

function isPlainArray(v: unknown): v is unknown[] {
  return Array.isArray(v) && v.every((i) =>
    i === null || typeof i !== 'object' || Object.getPrototypeOf(i) === Object.prototype)
}

Prevention

When it happens

Trigger: Reachable only if an array element causes isSerializable to return false silently. In practice the element-level checks throw before this line. Observed only with exotic element types or a framework regression.

Common situations: Rare. Possible with arrays containing Proxies, sparse arrays with holes, or arrays whose elements have been frozen/sealed in ways that interfere with traversal. Also possible from an internal serializer bug.

Related errors


AI-assisted analysis of vercel/next.js@0ae8c72462 (2026-08-06). Data as JSON: /api/errors/93bbebf4ea8b245b. Report an issue: GitHub.