I have a problem where a handler is being bundled ...
# help
r
I have a problem where a handler is being bundled with lots of code that is not referenced by that handler or by anything in its dependency tree. The structure we have is that there is a handlers folder, each file in there exports 1-to-many handlers. These handlers are pretty thin and call a service layer specific to their business logic. The reason I noticed this particular handler was bundling seemingly everything is that it barely does anything; simply calculating a value based on some inputs and returning but was erroring due to missing env vars for things it doesn’t reference. It’s like esbuild isn’t treeshaking at all. Does anyone have any idea of what could be causing that?
t
esbuild's treeshaking isn't as good as frontend bundlers like rollup
you can get a report with this:
Copy code
esbuild --minify --bundle --format=esm --target=esnext --external:aws-sdk  --platform=node ./backend/functions/graphql/graphql.ts --outfile=output.js --analyze=verbose
replace path with your function
r
Thanks, that helped pinpoint it. We were exporting each file from within a folder using an index file at the root of that folder. Even though only one of those was imported upstream, the whole lot was getting copied in.