Python deploy error: exceeded the unzipped maximum size of 250 MB

(To get it out of the way: Yes, I have searched and read the many topics for python function size here.)

I have a small python project/repo with no TS / Next.js / Django. When I run vercel build locally it produces a 43 MB .vercel/output but when I go to deploy I get the error: Error: A Serverless Function has exceeded the unzipped maximum size of 250 MB.

I can’t figure out why this error is happening or how to get past it! I’ve tried to hack du into the vercel.json *Commands to no avail. There is no debugging hooks or settings that I’ve been able to find otherwise which is quite frustrating. I tried using outputTracingIncludes per Error: A Serverless Function has exceeded the unzipped maximum size of 250 MB. : https://vercel.link/serverless-function-size - #2 by pawlean but that is Next.js specific

One possibility is that there may be some issues with local vs server module caching e.g. .uv-cache but I simply cannot figure out how to investigate that. My local .venv/lib is 198MB. (Even then, 43 + 198 = 241 < 250)

When I set VERCEL_BUILD_SYSTEM_REPORT=1 I get:

▲ Build system report
• No memory or disk space problems detected
• Folder sizes on disk:
  ‣ Input source code:     1 MB
  ‣ Build cache:          <1 MB
  ‣ Output files:          6 MB
  ‣ Node modules:        350 MB

I find the Node modules size very odd given that this is a pure python project/repo. Perhaps the python code is getting bundled into node somehow?

I already have excluded node_modules in my vercel.json

{
“$schema”: “https://openapi.vercel.sh/vercel.json”,
“functions”: {
“api/**/*": {
“excludeFiles”: "{.pnpm-store,.next,*.cache,node_modules,lib,collections,public,app}/**”
}
}
}

I also have an extensive .vercelignore including eg. **/*.pyc, .venv/** and so on.

Any debugging help would be greatly appreciate, I’d very much like to understand the root cause of the issue here.