zod
zod copied to clipboard
[v4] result is undefined when using _safeParse with rollup
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()],
};
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
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.