Here is a short, clean, blog‑friendly version that reflects your actual discovery:
How I Shrunk My Serverless Bundle by Discovering One Unexpected esbuild Issue
Today I finally solved a packaging problem that had bothered me for weeks:
no matter how many package.patterns I added — excluding Prisma engines, WASM files, TypeScript runtime, sourcemaps, caches — my AWS Lambda bundle never changed.
It didn’t matter if I excluded a few files or excluded everything.
The ZIP size stayed exactly the same.
Surprisingly, the fix had nothing to do with tree‑shaking, Prisma engine types, or exclude patterns.
The real culprit was something much simpler.
Problem: package.patterns didn’t work at all
I kept seeing massive files in the final ZIP:
-
@prisma/engines/** -
query_engine_bg.*.wasm-base64.js -
*.wasm -
typescript/** -
prisma/**
Even if I removed all patterns:
package:
patterns: []
The ZIP was still identical.
That meant Serverless was completely ignoring my configuration.
Root Cause: esbuild never ran
After turning on verbose mode:
npx serverless package --verbose
I saw no esbuild activity in the logs.
That’s when I realized:
My esbuild configuration was written under the wrong key.
I had something like:
custom:
something:
esbuild:
bundle: true
But the serverless-esbuild plugin only reads config in one of two places:
Correct option A
custom:
esbuild:
bundle: true
Correct option B (newer style)
esbuild:
bundle: true
Once I moved the config to the correct top‑level (sibling of custom):
esbuild:
bundle: true
minify: true
target: node20
— everything started working immediately.
Serverless finally invoked esbuild, generated .cjs bundles, and only then did package.patterns begin affecting the ZIP.
Important: This had nothing to do with Prisma engine type
I originally thought the fix required switching Prisma to:
engineType = "client"
But that wasn’t necessary at all.
The only real fix was:
✔️ Move esbuild: to the correct level in serverless.yml.
Once esbuild finally ran:
- The bundle size changed
- Patterns were applied correctly
- Unwanted files (WASM, engines, TypeScript) were finally excluded
- The ZIP output became predictable and small
Why this happens
serverless-esbuild only executes when it finds config at the correct path.
If the plugin can’t see your config:
- esbuild never runs
- Serverless zips raw source + raw node_modules
- All
package.patternsappear “broken” because they’re being applied to the wrong file structure - The ZIP never changes
Fixing the config path fixes everything.
Takeaway
If your Serverless bundle:
- is too big
- ignores your exclude rules
- keeps including Prisma engines, WASM, or TypeScript
- or looks unchanged no matter what you do
Check this first:
Is your esbuild: block in the correct location?
If not, nothing else will behave as expected.
This one small change made the entire packaging pipeline work properly again.
Top comments (0)