Thanks to visit codestin.com
Credit goes to github.com

Skip to content

4x bundle size increase with CommonJS for v4 and v4-mini vs v3 #4637

@paulbrimicombe

Description

@paulbrimicombe

When zod v3 is used in a CommonJS codebase that uses esbuild, rollup or webpack to package and minify code, the bundle size contribution of zod is ~68K which is pretty good. When v4 or v4-mini is used, the bundle size contribution increases more than 4x with the same project setup.

I've done some experiments with different bundlers and different versions of zod and here are some results:

Zod version Module system ESBuild bundle size Rollup bundle size Webpack bundle size
v3 CommonJS 68K 68K 68K
v4 CommonJS 288K 255K 254K
v4-mini CommonJS 279K 246K 245K
v3 ESM 55K 52K 52K
v4 ESM 41K 33K 35K
v4-mini ESM 41K 6K 33K 5K 35K 6K

This is a fairly major increase for anyone using this fairly common project setup (not just for front-end bundles — anyone using something like AWS Lambda will get slower cold starts due to the increased bundle size).

Note

ESM + v4-mini sizes fixed base on paulbrimicombe/zod-bundle-sizes#1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions