zod icon indicating copy to clipboard operation
zod copied to clipboard

[v4] result is undefined when using _safeParse with rollup

Open danny-boyer opened this issue 6 months ago • 1 comments

versions:
"@zod/core": "~0.11.6" "zod": "4.0.0-beta.20250505T195954"

Here is the generated code from rollup below

function _safeParse(schema, value, _ctx) {
    const ctx = _ctx ? { ..._ctx, async: false } : { async: false };
    const result = schema._zod.run({ value, issues: [] }, ctx);
    if (result instanceof Promise) {
        throw new $ZodAsyncError();
    }
    return (result.issues.length
        ? {
            success: false,
            error: new (this?.Error ?? $ZodError)(result.issues.map((iss) => finalizeIssue(iss, ctx, config()))),
        }
        : { success: true, data: result.value });
}

Cannot read properties of undefined (reading 'issues')

Is anyone able to reproduce this?

Rollup config

const commonjs = require("@rollup/plugin-commonjs");
const { nodeResolve } = require("@rollup/plugin-node-resolve");

module.exports = {
  input: {
    "order-action": "pos/targets/order-action.js",
    "order-modal": "pos/targets/order-modal.js",
    "smart-grid-modal": "pos/targets/smart-grid-modal.js",
    tile: "pos/targets/tile.js",
  },
  output: { dir: process.env.ROLLUP_OUTPUT_ROOT },
  plugins: [commonjs(), nodeResolve()],
};

danny-boyer avatar May 12 '25 18:05 danny-boyer

What's the code that you're bundling? Difficult to debug this otherwise.

Please also upgrade to the latest beta before you try again. You'll need to update your imports to zod/v4: https://github.com/colinhacks/zod/pull/4364

colinhacks avatar May 15 '25 00:05 colinhacks

This is unrelated to zod, the problem was that our process was bundling with rollup which was then bundled by a third party which had zod as well. So two zods of different versions were bundled.

danny-boyer avatar Jun 06 '25 00:06 danny-boyer