Skip to content

Bloating with esbuild bundled output #2596

@samratarmas

Description

@samratarmas

Hi Colin!

Awesome project, I came across this issue as referred by the following:

Originally posted by @gustavopch in #294 (comment)

The thread confirms your intention of having tree-shakable esm code, and it is marked as resolved and closed. However, esbuild currently bundles all of Zod into your output if you import a simple zod schema.

Steps to replicate:

  • Creating a simple ts project that uses esbuild with bundled output enabled.
  • Create a simple zod schema:

import {z} from "zod" const testSchema = z.string().min(10)

  • Validate some random string using the test schema
  • Build the project with esbuild using bundled output (also bundling external node_modules, so would be zod module in our case. This is currently how edge functions such as wrangler cli for cloudflare workers bundle ts, and the bundled code is several thousand lines of unused js from Zod in an edge environment supposed to be small and lightweight)

Another similar comment in thread:
Originally posted by @ekwoka in #294 (comment)

Is treeshaking working as expected? Looking forward to hearing from you,
Cheers!

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