fix: polyfill markAsUncloneable for Bun build compatibility - #1380
fix: polyfill markAsUncloneable for Bun build compatibility#1380github-actions[bot] wants to merge 1 commit into
Conversation
undici >= 8 (introduced on dev) unconditionally destructures markAsUncloneable from node:worker_threads without a fallback. Bun (Docker build stage) does not implement this Node.js 23+ API, so next build crashes during page data collection for proxy routes. Added a no-op polyfill imported before undici-dependent modules. CI Run: https://github.com/ding113/claude-code-hub/actions/runs/30714125452 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
| @@ -1,4 +1,5 @@ | |||
| import "@/lib/polyfills/file"; | |||
| import "@/lib/polyfills/worker-threads"; | |||
There was a problem hiding this comment.
Route-local shim leaves Undici exposed
When Next.js evaluates /api/actions before these proxy routes, its static actions/providers → gemini/auth chain loads Undici without this route-local shim, causing the Bun build to encounter the same missing markAsUncloneable failure. Initialize the shim from an application-wide server entrypoint that runs before every Undici import.
Knowledge Base Used: Proxy request pipeline
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/app/v1/[...route]/route.ts
Line: 2
Comment:
**Route-local shim leaves Undici exposed**
When Next.js evaluates `/api/actions` before these proxy routes, its static `actions/providers` → `gemini/auth` chain loads Undici without this route-local shim, causing the Bun build to encounter the same missing `markAsUncloneable` failure. Initialize the shim from an application-wide server entrypoint that runs before every Undici import.
**Knowledge Base Used:** [Proxy request pipeline](https://app.greptile.com/ygxz/-/custom-context/knowledge-base/ding113/claude-code-hub/-/docs/proxy-pipeline.md)
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6b173aa9ef
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| @@ -1,4 +1,5 @@ | |||
| import "@/lib/polyfills/file"; | |||
| import "@/lib/polyfills/worker-threads"; | |||
There was a problem hiding this comment.
Apply the worker shim before every undici entrypoint
In Bun Docker builds with undici 8, this side-effect import only protects the v1/v1beta route modules. I checked the retained /api/actions/[...route] legacy management route: it still statically imports @/actions/providers, which imports @/lib/proxy-agent and therefore undici at module load before any worker-threads shim runs, so Next's route/page data collection can hit the same markAsUncloneable crash after these two routes are fixed. Move the shim to a global server entrypoint or import it before every server entrypoint that can load undici.
Useful? React with 👍 / 👎.
CI Auto-Fix
Original PR: #1379
Failed CI Run: PR Build Check - Docker Build Test
Root Cause
The
devbranch upgradedundicito^8.9.0. When this PR is merged intodev, the CI merge picks up dev's undici version. Undici 8.x unconditionally destructuresmarkAsUncloneablefromnode:worker_threads(removed the runtime feature detection fallback that undici 7.x had):The Docker build stage uses
oven/bun:debian, and Bun does not implementmarkAsUncloneable(a Node.js 23+ API). This causesnext buildto crash during page data collection for/v1beta/[...route](and/v1/[...route]).This also affects
devdirectly - the latest dev Docker build (run 30712055253) also fails.Fixes Applied
src/lib/polyfills/worker-threads.ts(new)markAsUncloneableonnode:worker_threadswhen the runtime lacks itsrc/app/v1/[...route]/route.tssrc/app/v1beta/[...route]/route.tsVerification
bun run buildpasses withundici@8.9.0installed (previously crashed withTypeError: s.util.markAsUncloneable is not a function)bun run typecheckpassesbun run lintpassesmarkAsUncloneablealready exists)Auto-generated by Claude AI
Greptile Summary
The PR adds a Bun compatibility shim for the missing
worker_threads.markAsUncloneableAPI and loads it from the/v1and/v1betaproxy routes.Confidence Score: 4/5
This should be fixed before merging because another independently evaluated route can still load Undici before the compatibility shim and fail the Bun-based build.
The shim itself is conditional and preserves native behavior, but importing it only from two proxy routes does not cover the existing
/api/actionsroute chain that statically reaches Undici.Files Needing Attention: src/app/v1/[...route]/route.ts and src/app/v1beta/[...route]/route.ts
Important Files Changed
markAsUncloneablecompatibility shim without replacing native implementations./v1route wiring and has the same application-wide coverage limitation.Prompt To Fix All With AI
Reviews (1): Last reviewed commit: "fix: polyfill markAsUncloneable for Bun ..." | Re-trigger Greptile
Context used: