Skip to content

Preview fails with 'Cannot read properties of undefined (reading map)' in JSONSchemaFaker #9917

@ShivamGupta-SM

Description

@ShivamGupta-SM

Description

When using Novu Studio to preview workflows, the preview action fails with a 500 error. The error occurs in JSONSchemaFaker's internal validation when generating mock data from Zod schemas.

Environment

  • Novu Framework Version: 2.9.0
  • Node.js Version: 20.x
  • Platform: Windows 11
  • Bridge Setup: Encore.ts raw endpoint with Express adapter

Error Details

POST /api/novu?action=preview&workflowId=... 500

Error: Cannot read properties of undefined (reading 'map')
    at validateValueForSchema (chunk-ZF4VXELU.js)
    at ...JSONSchemaFaker internals...

The error originates from JSONSchemaFaker's validateValueForSchema function when processing certain schema types.

Steps to Reproduce

  1. Create a workflow with Zod schema validation:
import { workflow } from "@novu/framework";
import { z } from "zod";

const schema = z.object({
  userName: z.string().optional().default("there"),
  resetUrl: z.string().url(),
  expiresInHours: z.number().optional().default(24),
});

export const myWorkflow = workflow(
  "my-workflow",
  async ({ step, payload }) => {
    await step.email("send-email", async () => ({
      subject: "Test",
      body: "<p>Hello</p>",
    }));
  },
  { payloadSchema: schema }
);
  1. Sync workflows to Novu Cloud
  2. Open Novu Studio and try to preview the workflow
  3. Preview fails with 500 error

Expected Behavior

Preview should generate mock data from the schema and render the email template.

Actual Behavior

Preview returns 500 error. The JSONSchemaFaker bundled inside @novu/framework fails when calling .map() on an undefined value during schema validation.

Workaround

Direct API calls (via curl/Postman) work correctly. Only the Studio UI preview is affected.

Additional Context

  • The error is in the bundled JSONSchemaFaker inside node_modules/@novu/framework/dist/esm/chunk-ZF4VXELU.js
  • The mock() function calls Pt.generate() (JSONSchemaFaker) which fails on certain schema structures
  • Adding .default() values to Zod schemas does not resolve the issue

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions