Unable to use `zod` in coda packs (: e=>{this.issues=[...this.issues,e]} could not be cloned.)

I’m getting an error that looks like this while trying to use zod to validate incoming json. I have mostly identified the issue down to usage of transforms, but can’t be 100% sure

e=>{this.issues=[...this.issues,e]} could not be cloned.

It’s really hard to debug coda packs because I cannot reproduce the problem on my local computer. is there a way to reproduce coda pack’s runtime environment?

It’s not a perfect emulation, but when you run coda execute with the flag --vm=true it will run the code in a virtual machine that’s very close to the Packs runtime. When you install the SDK it attempts to install the isolated-vm dependency. If that succeeds it will use the VM, but if that fails it will silently fall back to running on Node directly. The isolated-vm dependency has a lot of system requirements, as outlined here:

Gotcha. Do you have an idea what the root cause of “object cannot be cloned” issue is?

Not exactly. Looking through the issues in the isolated-vm repo it seems like it could be related to restrictions on their end. I created a Pack that did some very simple Zod validation and it seemed to work fine when uploaded:

import * as coda from "@codahq/packs-sdk";
import { z } from "zod";

export const pack = coda.newPack();

pack.addFormula({
  name: "Test",
  description: "",
  parameters: [],
  resultType: coda.ValueType.String,
  execute: async function(args, context) {
    let response = await context.fetcher.fetch({
      method: "GET",
      url: "https://httpbin.org/get",
    });
    let data = response.body;
    const schema = z.object({
      headers: z.object({
        Accept: z.string(),
      }),
    });
    schema.parse(data);
    return "Done";
  },
});

pack.addNetworkDomain("httpbin.org");

Perhaps there is a specific feature of Zod causing this error?