-
-
Notifications
You must be signed in to change notification settings - Fork 386
fix: polyfill markAsUncloneable for Bun build compatibility #1380
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| import "@/lib/polyfills/file"; | ||
| import "@/lib/polyfills/worker-threads"; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
In Bun Docker builds with undici 8, this side-effect import only protects the v1/v1beta route modules. I checked the retained Useful? React with 👍 / 👎. |
||
| import { Hono } from "hono"; | ||
| import { handle } from "hono/vercel"; | ||
| import { registerCors } from "@/app/v1/_lib/cors"; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| import { createRequire } from "node:module"; | ||
|
|
||
| const nodeRequire = createRequire(import.meta.url); | ||
| const workerThreads = nodeRequire("node:worker_threads") as { | ||
| markAsUncloneable?: (...args: unknown[]) => void; | ||
| }; | ||
|
|
||
| // undici >= 8 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. | ||
| if (typeof workerThreads.markAsUncloneable !== "function") { | ||
| workerThreads.markAsUncloneable = function markAsUncloneable() {}; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When Next.js evaluates
/api/actionsbefore these proxy routes, its staticactions/providers→gemini/authchain loads Undici without this route-local shim, causing the Bun build to encounter the same missingmarkAsUncloneablefailure. 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