HeadlinesBriefing favicon HeadlinesBriefing.com

Fixing Serverless esbuild Prisma Bundle Size

DEV Community •
×

A developer finally cracked a persistent AWS Lambda packaging issue where Prisma engines and WASM files bloated their deployment ZIP. Despite exhaustive `package.patterns` exclusions, the bundle size remained unchanged. The breakthrough came after discovering that their esbuild configuration was nested incorrectly within the `serverless.yml` file, causing the entire build process to silently fail.

The root cause was simple but maddening: the `serverless-esbuild` plugin requires its configuration at a specific top-level path. Placed under `custom` or other keys, the plugin simply never executed. Without esbuild running, Serverless Framework zipped raw source code and complete `node_modules`, rendering all optimization attempts useless and leaving developers debugging the wrong problem.

Once the configuration was moved to the correct root level alongside `custom`, the plugin sprang to life. Bundles shrunk immediately as esbuild processed the code and `package.patterns` finally took effect. This experience serves as a crucial reminder for Serverless users: if your pipeline seems broken, double-check that your build tools are actually receiving their instructions before chasing complex workarounds.