How I Finally Fixed My Serverless + esbuild + Prisma Packaging Nightmare

Source: Dev.to | Jan 15, 2026 (UTC)

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: []

Enter fullscreen mode

Exit fullscreen mode

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

Enter fullscreen mode

Exit fullscreen mode

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

Enter fullscreen mode

Exit fullscreen mode

But the serverless-esbuild plugin only reads config in one of two places:

Correct option A

custom: esbuild: bundle: true

Enter fullscreen mode

Exit fullscreen mode

Correct option B (newer style)

esbuild: bundle: true

Enter fullscreen mode

Exit fullscreen mode

Once I moved the config to the correct top‑level (sibling of custom):

esbuild: bundle: true minify: true target: node20

Enter fullscreen mode

Exit fullscreen mode

— 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"

Enter fullscreen mode

Exit fullscreen mode

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:

Why this happens

serverless-esbuild only executes when it finds config at the correct path.

If the plugin can’t see your config:

  1. esbuild never runs
  2. Serverless zips raw source + raw node_modules
  3. All package.patterns appear “broken” because they’re being applied to the wrong file structure
  4. The ZIP never changes

Fixing the config path fixes everything.

Takeaway

If your Serverless bundle:

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.

For further actions, you may consider blocking this person and/or reporting abuse

Залишити відповідь

Ваша e-mail адреса не оприлюднюватиметься. Обов’язкові поля позначені *

Читайте також