# ESBuild Bundling not working?

**URL:** <https://forum.serverless.com/t/esbuild-bundling-not-working/20597>\
**Category:** Serverless Framework\
**Created:** [September 28, 2024, 8:17pm UTC](https://forum.serverless.com/t/esbuild-bundling-not-working/20597 "2024-09-28T20:17:44Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![rowan-carlsen](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/rowan-carlsen/32/8079_2.png) [@rowan-carlsen](https://forum.serverless.com/u/rowan-carlsen)\
**Post date:** [September 28, 2024, 8:17pm UTC](https://forum.serverless.com/t/esbuild-bundling-not-working/20597/1 "2024-09-28T20:17:44Z")

</div>

Hello! I’m trying to understand the options Serverless v4 provides, and I’m getting very confused about the esbuild implementation. Our functions that were bundling to ~5MB in v3 are now ~75MB, far over the lambda size limit (and obviously just unnecessarily big). That is with 0 configuration of the build.

If I add ANY options under the new

```auto
build:
  esbuild:

```

heading in serverless.yml, it instead makes the function .zips about 10KB and doesn’t include ANY dependencies whatsoever. I’ve tried just about everything in terms of trying out options like “packages:”, “exclude:”, “external:”, etc. I’m really just looking to replicate the same build results we were getting in v3, and I’ve pored over the docs a ton by now.

---

<div class="post-metadata">

**Author:** ![TomC](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/tomc/32/4002_2.png) [@TomC](https://forum.serverless.com/u/TomC)\
**Post date:** [September 30, 2024, 4:24pm UTC](https://forum.serverless.com/t/esbuild-bundling-not-working/20597/2 "2024-09-30T16:24:21Z")

</div>

You mean you are doing [Build Config - Function Build Configuration](https://www.serverless.com/framework/docs/providers/aws/guide/building) right ?

But all your code is actually _not_ TypeScript ?

Have you tried this on a greenfield project, starting with TypeScript files and the build option ?

---

<div class="post-metadata">

**Author:** ![rowan-carlsen](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/rowan-carlsen/32/8079_2.png) [@rowan-carlsen](https://forum.serverless.com/u/rowan-carlsen)\
**Post date:** [September 30, 2024, 4:40pm UTC](https://forum.serverless.com/t/esbuild-bundling-not-working/20597/3 "2024-09-30T16:40:20Z")

</div>

Thanks for the reply!

We are upgrading a number of services to Serverless v4 from v3 - none have ever used TypeScript, and we’re not planning to use it. I didn’t get the impression that was the only or main purpose of the build config. We are simply trying to get bundles for our lambda functions that are roughly the same size as they were using v3. Currently they’re over 10x as large, unless we set _any_ of the build config settings (that you linked), in which case they are extremely tiny and missing package.json and node\_modules entirely.

---

<div class="post-metadata">

**Author:** ![TomC](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/tomc/32/4002_2.png) [@TomC](https://forum.serverless.com/u/TomC)\
**Post date:** [September 30, 2024, 4:53pm UTC](https://forum.serverless.com/t/esbuild-bundling-not-working/20597/4 "2024-09-30T16:53:57Z")

</div>

Ah, ha OK, that makes sense.

I wouldn’t set this new build option in that case.

I suspect, and this has happened to us too, that some dependency is pulling in either the whole of Serverless or (parts of) AWS SDK.

Firstly, check `dependencies` and `devDependencies` in `package.json` just to rule out that.

Then you can unzip the deployment zip and have a look for the (largest) sub folders.

If you see it _is_ bundling something it didn’t before, then try something like `npm ll` or `npm ll --all` to see what is pulling it in.

- List item

---

<div class="post-metadata">

**Author:** ![rowan-carlsen](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/rowan-carlsen/32/8079_2.png) [@rowan-carlsen](https://forum.serverless.com/u/rowan-carlsen)\
**Post date:** [September 30, 2024, 5:47pm UTC](https://forum.serverless.com/t/esbuild-bundling-not-working/20597/5 "2024-09-30T17:47:25Z")

</div>

I unzipped one of the deployed functions (made locally with `sls package --package`) and analyzed it as you suggested. It’s including **all** dev dependencies - in fact it simply copy + pasted the entirety of the node\_modules folder from the project’s base directory. I have NOT altered the default excludeDevDependencies option, or really added any config at all. My serverless.yml only has

```auto
package:
  individually: true

```

, everything else is just the functions and domain setup, nothing to do with build/packaging. It doesn’t seem like any bundling or building is happening at all, really.

---

<div class="post-metadata">

**Author:** ![TomC](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/tomc/32/4002_2.png) [@TomC](https://forum.serverless.com/u/TomC)\
**Post date:** [October 1, 2024, 7:46am UTC](https://forum.serverless.com/t/esbuild-bundling-not-working/20597/6 "2024-10-01T07:46:38Z")

</div>

Well, that’s odd. Does removing that line help at all ?

---

<div class="post-metadata">

**Author:** ![rowan-carlsen](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/rowan-carlsen/32/8079_2.png) [@rowan-carlsen](https://forum.serverless.com/u/rowan-carlsen)\
**Post date:** [October 1, 2024, 2:33pm UTC](https://forum.serverless.com/t/esbuild-bundling-not-working/20597/7 "2024-10-01T14:33:16Z")

</div>

Not really - basically the same behavior without individual function packages. It produces one 75 MB bundle instead of two or more, which I guess is better, but still over deployment limit.

For anyone coming to this topic seeing similar issues, we did find a stopgap solution. We were able to return to our old bundling config while still using Serverless v4 by adding:

```auto
build:
esbuild: false

```

and then putting back in the serverless-esbuild plugin (and esbuild-node-externals package) and the properties under “custom” that made our output ESM instead of CJS. Back down to ~5 MB function bundles. But we definitely would like to see the native esbuild part of Serverless v4 working in the future, as well as things like excluding dev dependencies.

---

<div class="post-metadata">

**Author:** ![tbehunin](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/tbehunin/32/3475_2.png) [@tbehunin](https://forum.serverless.com/u/tbehunin)\
**Post date:** [October 11, 2024, 6:35pm UTC](https://forum.serverless.com/t/esbuild-bundling-not-working/20597/8 "2024-10-11T18:35:35Z")

</div>

Yeah I’ve struggled to get the built-in Serverless ESBuild to work too and I’ve just resorted to turning it off and using the serverless-esbuild plugin instead. Looks like that feature wasn’t ready for prime time.

---

<div class="post-metadata">

**Author:** ![garethmcc](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/garethmcc/32/2276_2.png) [@garethmcc](https://forum.serverless.com/u/garethmcc)\
**Post date:** [October 22, 2024, 10:15am UTC](https://forum.serverless.com/t/esbuild-bundling-not-working/20597/9 "2024-10-22T10:15:45Z")

</div>

Would you mind providing a little more detail as to the issue you ran into? We have continued to make updates due to user feedback (and the issues you experienced may already be addressed) but would like to tackle more if we can
